From patchwork Tue Aug 15 09:52:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 9901525 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 E933F60244 for ; Tue, 15 Aug 2017 09:52:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9E3028822 for ; Tue, 15 Aug 2017 09:52:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC26928815; Tue, 15 Aug 2017 09:52:46 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 4514828815 for ; Tue, 15 Aug 2017 09:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753470AbdHOJwp (ORCPT ); Tue, 15 Aug 2017 05:52:45 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:44559 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753395AbdHOJwp (ORCPT ); Tue, 15 Aug 2017 05:52:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=avSYlT2vd1GeciLmgtT1B5BcCCTNRIbQR1uOPYKHO5I=; b=YuwWJrSsG7y15T9VHt5C3larS VTRI8z6q3Tr9XtUgPwvAuS75esWwjweo3XUVbxpIoo3pn86/eJJidmtY7J+lg0ydE7UbuA+MZK8ER ZQlrODwKmC9zszo2pYD9db+xq4YpfzNWqTcCM6M6hGeLb2nRnzj+HNpBdh9+0I2xZ5hnztPWWOzls dQK8Bw80hstptDrBnMbYvEyZqp4BazSnT5TqGNnwzfjeoX228PrIQTadtVqapyZUA30LS8h8ifRxc THHcW5/MT/UbDlwi/Z241dDF6ArX2t1ku5xPLy3zh4t9b6QOhjDE6g3CNDhCpfk1kF76SZlt/qWP5 rrqEDYhEA==; Received: from bzq-82-81-101-184.red.bezeqint.net ([82.81.101.184] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dhYWg-0007Bp-04; Tue, 15 Aug 2017 09:52:42 +0000 From: Sagi Grimberg To: linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch Cc: linux-block@vger.kernel.org Subject: [PATCH 07/12] nvme-rdma: split generic probe out of create_ctrl Date: Tue, 15 Aug 2017 12:52:20 +0300 Message-Id: <1502790745-12569-8-git-send-email-sagi@grimberg.me> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502790745-12569-1-git-send-email-sagi@grimberg.me> References: <1502790745-12569-1-git-send-email-sagi@grimberg.me> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This code is replicated for several transports, prepare to move it to the core. Signed-off-by: Sagi Grimberg --- drivers/nvme/host/rdma.c | 81 ++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 2591b0ce155e..b03c4a2a1172 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1908,12 +1908,51 @@ static int nvme_rdma_post_configure(struct nvme_ctrl *ctrl) return 0; } +static int nvme_rdma_probe_ctrl(struct nvme_ctrl *ctrl, struct device *dev, + const struct nvme_ctrl_ops *ops, unsigned long quirks) +{ + bool changed; + int ret; + + ret = nvme_init_ctrl(ctrl, dev, ops, quirks); + if (ret) + return ret; + + INIT_WORK(&ctrl->delete_work, nvme_rdma_del_ctrl_work); + INIT_WORK(&ctrl->reset_work, nvme_rdma_reset_ctrl_work); + + ret = nvme_rdma_configure_admin_queue(ctrl, true); + if (ret) + goto out_uninit_ctrl; + + ret = nvme_rdma_post_configure(ctrl); + if (ret) + goto out_remove_admin_queue; + + if (ctrl->queue_count > 1) { + ret = nvme_rdma_configure_io_queues(ctrl, true); + if (ret) + goto out_remove_admin_queue; + } + + changed = nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE); + WARN_ON_ONCE(!changed); + + nvme_start_ctrl(ctrl); + + return 0; +out_remove_admin_queue: + nvme_rdma_destroy_admin_queue(ctrl, true); +out_uninit_ctrl: + nvme_uninit_ctrl(ctrl); + return ret; +} + static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) { struct nvme_rdma_ctrl *ctrl; int ret; - bool changed; char *port; ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); @@ -1948,39 +1987,20 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, } } - ret = -ENOMEM; ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), GFP_KERNEL); - if (!ctrl->queues) + if (!ctrl->queues) { + ret = -ENOMEM; goto out_free_ctrl; - - ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, - 0 /* no quirks, we're perfect! */); - if (ret) - goto out_kfree_queues; + } INIT_DELAYED_WORK(&ctrl->ctrl.reconnect_work, nvme_rdma_reconnect_ctrl_work); INIT_WORK(&ctrl->ctrl.err_work, nvme_rdma_error_recovery_work); - INIT_WORK(&ctrl->ctrl.delete_work, nvme_rdma_del_ctrl_work); - INIT_WORK(&ctrl->ctrl.reset_work, nvme_rdma_reset_ctrl_work); - - ret = nvme_rdma_configure_admin_queue(&ctrl->ctrl, true); - if (ret) - goto out_uninit_ctrl; - - ret = nvme_rdma_post_configure(&ctrl->ctrl); - if (ret) - goto out_uninit_ctrl; - if (opts->nr_io_queues) { - ret = nvme_rdma_configure_io_queues(&ctrl->ctrl, true); - if (ret) - goto out_remove_admin_queue; - } - - changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); - WARN_ON_ONCE(!changed); + ret = nvme_rdma_probe_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, 0); + if (!ctrl->queues) + goto out_kfree_queues; dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n", ctrl->ctrl.opts->subsysnqn, &ctrl->addr); @@ -1991,21 +2011,14 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list); mutex_unlock(&nvme_rdma_ctrl_mutex); - nvme_start_ctrl(&ctrl->ctrl); - return &ctrl->ctrl; -out_remove_admin_queue: - nvme_rdma_destroy_admin_queue(&ctrl->ctrl, true); out_kfree_queues: kfree(ctrl->queues); -out_uninit_ctrl: - nvme_uninit_ctrl(&ctrl->ctrl); +out_free_ctrl: nvme_put_ctrl(&ctrl->ctrl); if (ret > 0) ret = -EIO; - return ERR_PTR(ret); -out_free_ctrl: kfree(ctrl); return ERR_PTR(ret); }