From patchwork Thu Dec 6 16:48:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 10716361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CDE917DB for ; Thu, 6 Dec 2018 16:48:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A6D12F0BF for ; Thu, 6 Dec 2018 16:48:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D82D2F0C2; Thu, 6 Dec 2018 16:48:28 +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 C6ED32F0BF for ; Thu, 6 Dec 2018 16:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbeLFQsY (ORCPT ); Thu, 6 Dec 2018 11:48:24 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44120 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbeLFQsY (ORCPT ); Thu, 6 Dec 2018 11:48:24 -0500 Received: from [191.13.27.189] (helo=calabresa.spo.virtua.com.br) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1gUwp4-0000io-90; Thu, 06 Dec 2018 16:48:22 +0000 From: Thadeu Lima de Souza Cascardo To: linux-nvme@lists.infradead.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Jens Axboe Subject: [PATCH 2/4] nvme: create slaves/holder entries for multipath devices Date: Thu, 6 Dec 2018 14:48:10 -0200 Message-Id: <20181206164812.30925-3-cascardo@canonical.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181206164812.30925-1-cascardo@canonical.com> References: <20181206164812.30925-1-cascardo@canonical.com> MIME-Version: 1.0 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 From: Christoph Hellwig This allows tools like distro installers easily track the relationship. Signed-off-by: Christoph Hellwig [cascardo: only add disk when there is ns->head] Signed-off-by: Thadeu Lima de Souza Cascardo Reviewed-by: Hannes Reinecke --- drivers/nvme/host/core.c | 5 +++-- drivers/nvme/host/multipath.c | 13 +++++++++++-- drivers/nvme/host/nvme.h | 12 ++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 3ce7fc9df378..1dc29795f1ee 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -371,7 +371,7 @@ static void nvme_free_ns_head(struct kref *ref) struct nvme_ns_head *head = container_of(ref, struct nvme_ns_head, ref); - nvme_mpath_remove_disk(head); + nvme_mpath_remove_nshead(head); ida_simple_remove(&head->subsys->ns_ida, head->instance); list_del_init(&head->entry); cleanup_srcu_struct_quiesced(&head->srcu); @@ -3120,7 +3120,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups); - nvme_mpath_add_disk(ns, id); + nvme_mpath_add_ns(ns, id); nvme_fault_inject_init(ns); kfree(id); @@ -3144,6 +3144,7 @@ static void nvme_ns_remove(struct nvme_ns *ns) nvme_fault_inject_fini(ns); if (ns->disk && ns->disk->flags & GENHD_FL_UP) { + nvme_mpath_remove_ns(ns); del_gendisk(ns->disk); blk_cleanup_queue(ns->queue); if (blk_get_integrity(ns->disk)) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index ec310b1b9267..174c64643592 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -500,7 +500,7 @@ static int nvme_set_ns_ana_state(struct nvme_ctrl *ctrl, return 0; } -void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id) +void nvme_mpath_add_ns(struct nvme_ns *ns, struct nvme_id_ns *id) { if (nvme_ctrl_use_ana(ns->ctrl)) { mutex_lock(&ns->ctrl->ana_lock); @@ -513,9 +513,18 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id) nvme_mpath_set_live(ns); mutex_unlock(&ns->head->lock); } + + if (ns->head->disk) + bd_link_disk_holder(&ns->disk->part0, ns->head->disk); +} + +void nvme_mpath_remove_ns(struct nvme_ns *ns) +{ + if (ns->head->disk) + bd_unlink_disk_holder(&ns->disk->part0, ns->head->disk); } -void nvme_mpath_remove_disk(struct nvme_ns_head *head) +void nvme_mpath_remove_nshead(struct nvme_ns_head *head) { if (!head->disk) return; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index ae77eb16fd1f..365262d11e53 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -470,8 +470,9 @@ void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, void nvme_failover_req(struct request *req); void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl); int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head); -void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id); -void nvme_mpath_remove_disk(struct nvme_ns_head *head); +void nvme_mpath_add_ns(struct nvme_ns *ns, struct nvme_id_ns *id); +void nvme_mpath_remove_ns(struct nvme_ns *ns); +void nvme_mpath_remove_nshead(struct nvme_ns_head *head); int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id); void nvme_mpath_uninit(struct nvme_ctrl *ctrl); void nvme_mpath_stop(struct nvme_ctrl *ctrl); @@ -515,11 +516,14 @@ static inline int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, { return 0; } -static inline void nvme_mpath_add_disk(struct nvme_ns *ns, +static inline void nvme_mpath_add_ns(struct nvme_ns *ns, struct nvme_id_ns *id) { } -static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head) +static inline void nvme_mpath_remove_ns(struct nvme_ns *ns) +{ +} +static inline void nvme_mpath_remove_nshead(struct nvme_ns_head *head) { } static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns)