From patchwork Sat Feb 6 03:36:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 12071863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9ED9C433E0 for ; Sat, 6 Feb 2021 03:38:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FB4264F9D for ; Sat, 6 Feb 2021 03:38:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FB4264F9D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8EQk-0007ec-FE for qemu-devel@archiver.kernel.org; Fri, 05 Feb 2021 22:38:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8EOs-0005nw-13; Fri, 05 Feb 2021 22:36:46 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:33804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8EOq-0003go-4v; Fri, 05 Feb 2021 22:36:45 -0500 Received: by mail-pl1-x631.google.com with SMTP id u15so4565613plf.1; Fri, 05 Feb 2021 19:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S9rN2Kzxfipm4/AIkXB8mqZYbmUbYQoOU2bvhW0ijBI=; b=dYFZGp62N++FUxPLyRqXcSF2ZYiOUh3l9oXiwrJiQL/x63VpPYIZJNgO47l/BXooGw eZWm3KQllVBjojhjVhp+bt39dnHMXTl+k2udaZ4f2eanCi6DNU9vA6+75K96mhE6OLxt dVYB+1D9eLPq+QS1CCp3lVAtsUr6rkb8gOELStHx2ZOT+zlLxyq6BulQ5+YMJokC4kPI rbCTaGJm5BDfGcV4Ym58j73EBLrdpUc5fWKzSCaEinzrZQ0ruXWMUAPvWwvOCbO7sJiu EiVJ1XL4SslvTVNMgkOBdjo8O6tEtf3Nf7+JTLgUwraKUb9kM7Luw5ZhA688l7HtiUPz c7DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S9rN2Kzxfipm4/AIkXB8mqZYbmUbYQoOU2bvhW0ijBI=; b=jOyO3pCpFsRiQwIV4g4uegIa0Z/Mk5Kh2KlKMkk/fjnZiaLalxq3PY9mKpN1sfFkMc 1Dtc0BigsnCYH8LXZ9+Vkl5MxrKtHxwy415WVfsqhYVK2xrRe4E1xekHymGmTL1vACGA vcrV0z2FSFPM6vZQMv+kG4Ma3x2RisvsLUM+UZdI8d175oO/awOVodZrNpkytj606uDn 6Hy+d9mvBysHKDT3KbZIYn7avBmFHrvMzO9I8sirlFKCq1Qb4x6idSQB+89xVKWoRpt0 SMviitByKzkV+nSCDkqScs2f+TikxIDfdeq/WT1mFSstFCBFe/dFTP7uvPob/gaz9ETS vUgg== X-Gm-Message-State: AOAM533JmklOFtEgCFtr5MnRYMlYjPEJ16nhlGVJh0MUdJt5DIDidTS7 AvB10/raa8txB/PT+oTTqRQGoWyFCFWVDQ== X-Google-Smtp-Source: ABdhPJzRzjFbp+CGhAMVBjpenjF6OKXCsFl8Sv1oB0SU01uekv5bTWwKVmHwM4Gtwucc63na+lhaaQ== X-Received: by 2002:a17:90a:9414:: with SMTP id r20mr7092917pjo.158.1612582601101; Fri, 05 Feb 2021 19:36:41 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id j17sm10862375pfh.183.2021.02.05.19.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 19:36:40 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH 1/6] hw/block/nvme: support namespace detach Date: Sat, 6 Feb 2021 12:36:24 +0900 Message-Id: <20210206033629.4278-2-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210206033629.4278-1-minwoo.im.dev@gmail.com> References: <20210206033629.4278-1-minwoo.im.dev@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=minwoo.im.dev@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Keith Busch , Klaus Jensen , Minwoo Im , Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Given that now we have nvme-subsys device supported, we can manage namespace allocated, but not attached: detached. This patch introduced a parameter for nvme-ns device named 'detached'. This parameter indicates whether the given namespace device is detached from a entire NVMe subsystem('subsys' given case, shared namespace) or a controller('bus' given case, private namespace). - Allocated namespace 1) Shared ns in the subsystem 'subsys0': -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,subsys=subsys0,detached=true 2) Private ns for the controller 'nvme0' of the subsystem 'subsys0': -device nvme-subsys,id=subsys0 -device nvme,serial=foo,id=nvme0,subsys=subsys0 -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true 3) (Invalid case) Controller 'nvme0' has no subsystem to manage ns: -device nvme,serial=foo,id=nvme0 -device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true Signed-off-by: Minwoo Im --- hw/block/nvme-ns.c | 1 + hw/block/nvme-ns.h | 1 + hw/block/nvme-subsys.h | 1 + hw/block/nvme.c | 41 +++++++++++++++++++++++++++++++++++++++-- hw/block/nvme.h | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index c3b513b0fc78..cdcb81319fb5 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -393,6 +393,7 @@ static Property nvme_ns_props[] = { DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf), DEFINE_PROP_LINK("subsys", NvmeNamespace, subsys, TYPE_NVME_SUBSYS, NvmeSubsystem *), + DEFINE_PROP_BOOL("detached", NvmeNamespace, params.detached, false), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid), DEFINE_PROP_UINT16("mssrl", NvmeNamespace, params.mssrl, 128), diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 7af6884862b5..b0c00e115d81 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -26,6 +26,7 @@ typedef struct NvmeZone { } NvmeZone; typedef struct NvmeNamespaceParams { + bool detached; uint32_t nsid; QemuUUID uuid; diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index ccf6a71398d3..890d118117dc 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -23,6 +23,7 @@ typedef struct NvmeSubsystem { uint8_t subnqn[256]; NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; + /* Allocated namespaces for this subsystem */ NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES]; } NvmeSubsystem; diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 6b84e34843f5..a1e930f7c8e4 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -23,7 +23,7 @@ * max_ioqpairs=, \ * aerl=, aer_max_queued=, \ * mdts=,zoned.append_size_limit=, \ - * subsys= \ + * subsys=,detached= * -device nvme-ns,drive=,bus=,nsid=,\ * zoned=, \ * subsys= @@ -78,6 +78,13 @@ * controllers in the subsystem. Otherwise, `bus` must be given to attach * this namespace to a specified single controller as a non-shared namespace. * + * - `detached` + * Not to attach the namespace device to controllers in the NVMe subsystem + * during boot-up. If not given, namespaces are all attahced to all + * controllers in the subsystem by default. + * It's mutual exclusive with 'bus' parameter. It's only valid in case + * `subsys` is provided. + * * Setting `zoned` to true selects Zoned Command Set at the namespace. * In this case, the following namespace properties are available to configure * zoned operation: @@ -4521,6 +4528,20 @@ static void nvme_init_state(NvmeCtrl *n) n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); } +static int nvme_attach_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) +{ + if (nvme_ns_is_attached(n, ns)) { + error_setg(errp, + "namespace %d is already attached to controller %d", + nvme_nsid(ns), n->cntlid); + return -1; + } + + nvme_ns_attach(n, ns); + + return 0; +} + int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) { uint32_t nsid = nvme_nsid(ns); @@ -4552,7 +4573,23 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) trace_pci_nvme_register_namespace(nsid); - n->namespaces[nsid - 1] = ns; + /* + * If subsys is not given, namespae is always attached to the controller + * because there's no subsystem to manage namespace allocation. + */ + if (!n->subsys) { + if (ns->params.detached) { + error_setg(errp, + "detached needs nvme-subsys specified nvme or nvme-ns"); + return -1; + } + + return nvme_attach_namespace(n, ns, errp); + } else { + if (!ns->params.detached) { + return nvme_attach_namespace(n, ns, errp); + } + } return 0; } diff --git a/hw/block/nvme.h b/hw/block/nvme.h index cb2b5175f1a1..bde0ed7c2679 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -176,6 +176,10 @@ typedef struct NvmeCtrl { NvmeSubsystem *subsys; NvmeNamespace namespace; + /* + * Attached namespaces to this controller. If subsys is not given, all + * namespaces in this list will always be attached. + */ NvmeNamespace *namespaces[NVME_MAX_NAMESPACES]; NvmeSQueue **sq; NvmeCQueue **cq; @@ -194,6 +198,24 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid) return n->namespaces[nsid - 1]; } +static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns) +{ + int nsid; + + for (nsid = 1; nsid <= n->num_namespaces; nsid++) { + if (nvme_ns(n, nsid) == ns) { + return true; + } + } + + return false; +} + +static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid(ns) - 1] = ns; +} + static inline NvmeCQueue *nvme_cq(NvmeRequest *req) { NvmeSQueue *sq = req->sq;