Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3642006imm; Mon, 18 Jun 2018 01:23:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKKIrPc48y9e9X+XGo/CZd6LJ5riuhSF6uPxvXhfUUUUBrRSPLiPa+MZzq5TSA1tnErGQ4X X-Received: by 2002:a63:6f89:: with SMTP id k131-v6mr10246426pgc.345.1529310233918; Mon, 18 Jun 2018 01:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529310233; cv=none; d=google.com; s=arc-20160816; b=sa2mPcqnrVSAsKEksZxqFk41oxE2Nus6VvJgJtCxQiimM2ildUSki1rw+GC9E1sFY4 gjLeafwuxgo6g40Itk4SvllUUUU9wPUrym30Y65or2UIl16ux52DPUgBG5l7Ox53yRqP G5SD4YHAdNjFQKKyLIBA4OWYJU1ck+XwVSrhIUMqruVyxrYZon9iVwMyDoqylG1LSFDP iQRpNvhcKBu9l3KXKTRyaU6696yvfU9RhyDpncERa2D8eseXN6tY7I8ouiqPEgkpklYG t4IemVdXxvhBDyQXpi7Dee5u1SLGX7SX9hi+tq6Cj8hFlN7mmQzjvHaOqACSl0okevmd H4XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=+JNRFYy33IUCXH/Sbt3kypJ5LBSi8CdhT4DbAWoTw+g=; b=liSulQbYLKREYk/gzdBNNdwjMcX7FJx6o6FfsSvy7tE+FOWGOwFImEAe4PyrzdETx3 lhJFunbm1ksItPYpLpaiESCHMJ/O4x7gj9RpX1aRISJgvDz8e40OV/SZdEywmWGKEMGC wol7KHBFI6q2yQZFnLTF128H9wD4U3bXizkywrt9kHO6vwICWJmJzPTripDx112JUXlQ 03CDgR49goMkhGsXpNSy/CUm+z0M4jssngfP6SS1zU5Dd32nQaKjY8IMU59369bkiPf+ rk362So0zAmA1FWfAOUK5DJA8qCXP3Yuj0IG0o0rp6QlKaQYmRInZcUNNiZxGQE39KNG oFUw== 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 l9-v6si14978861pfa.368.2018.06.18.01.23.40; Mon, 18 Jun 2018 01:23:53 -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 S964989AbeFRIXI (ORCPT + 99 others); Mon, 18 Jun 2018 04:23:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55702 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965687AbeFRIXE (ORCPT ); Mon, 18 Jun 2018 04:23:04 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id ED271BAD; Mon, 18 Jun 2018 08:23:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Snitzer , Keith Busch , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 4.16 168/279] nvme/multipath: Fix multipath disabled naming collisions Date: Mon, 18 Jun 2018 10:12:33 +0200 Message-Id: <20180618080615.774751763@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Keith Busch [ Upstream commit a785dbccd95c37606c720580714f5a7a8b3255f1 ] When CONFIG_NVME_MULTIPATH is set, but we're not using nvme to multipath, namespaces with multiple paths were not creating unique names due to reusing the same instance number from the namespace's head. This patch fixes this by falling back to the non-multipath naming method when the parameter disabled using multipath. Reported-by: Mike Snitzer Signed-off-by: Keith Busch Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/core.c | 26 +------------------------- drivers/nvme/host/multipath.c | 22 ++++++++++++++++++++++ drivers/nvme/host/nvme.h | 12 ++++++++++++ 3 files changed, 35 insertions(+), 25 deletions(-) --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2979,31 +2979,7 @@ static void nvme_alloc_ns(struct nvme_ct if (nvme_init_ns_head(ns, nsid, id)) goto out_free_id; nvme_setup_streams_ns(ctrl, ns); - -#ifdef CONFIG_NVME_MULTIPATH - /* - * If multipathing is enabled we need to always use the subsystem - * instance number for numbering our devices to avoid conflicts - * between subsystems that have multiple controllers and thus use - * the multipath-aware subsystem node and those that have a single - * controller and use the controller node directly. - */ - if (ns->head->disk) { - sprintf(disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, - ctrl->cntlid, ns->head->instance); - flags = GENHD_FL_HIDDEN; - } else { - sprintf(disk_name, "nvme%dn%d", ctrl->subsys->instance, - ns->head->instance); - } -#else - /* - * But without the multipath code enabled, multiple controller per - * subsystems are visible as devices and thus we cannot use the - * subsystem instance. - */ - sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance); -#endif + nvme_set_disk_name(disk_name, ns, ctrl, &flags); if ((ctrl->quirks & NVME_QUIRK_LIGHTNVM) && id->vs[0] == 0x1) { if (nvme_nvm_register(ns, disk_name, node)) { --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -19,6 +19,28 @@ module_param(multipath, bool, 0444); MODULE_PARM_DESC(multipath, "turn on native support for multiple controllers per subsystem"); +/* + * If multipathing is enabled we need to always use the subsystem instance + * number for numbering our devices to avoid conflicts between subsystems that + * have multiple controllers and thus use the multipath-aware subsystem node + * and those that have a single controller and use the controller node + * directly. + */ +void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, + struct nvme_ctrl *ctrl, int *flags) +{ + if (!multipath) { + sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance); + } else if (ns->head->disk) { + sprintf(disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, + ctrl->cntlid, ns->head->instance); + *flags = GENHD_FL_HIDDEN; + } else { + sprintf(disk_name, "nvme%dn%d", ctrl->subsys->instance, + ns->head->instance); + } +} + void nvme_failover_req(struct request *req) { struct nvme_ns *ns = req->q->queuedata; --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -411,6 +411,8 @@ extern const struct attribute_group nvme extern const struct block_device_operations nvme_ns_head_ops; #ifdef CONFIG_NVME_MULTIPATH +void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, + struct nvme_ctrl *ctrl, int *flags); void nvme_failover_req(struct request *req); bool nvme_req_needs_failover(struct request *req, blk_status_t error); void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl); @@ -436,6 +438,16 @@ static inline void nvme_mpath_check_last } #else +/* + * Without the multipath code enabled, multiple controller per subsystems are + * visible as devices and thus we cannot use the subsystem instance. + */ +static inline void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, + struct nvme_ctrl *ctrl, int *flags) +{ + sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance); +} + static inline void nvme_failover_req(struct request *req) { }