From nobody Tue Nov 18 15:24:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1611076966; cv=none; d=zohomail.com; s=zohoarc; b=Uin2lFLnF3mgnkv17TW+HfEGKAMbFybtJ5zJmCFGN45z42u0VsM4MPDNdq2RlvpRKBVELXs0uKQtrbISmAgw4JjtsSk5VEX8OlgGb1cJjZk0RLAXVk5j5+DBdByT2PdM6e3UZrrY5rElEWR6/VUF2JaPvqiK1D79SIb55Mcy7jU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611076966; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5ZLkaxx2eM6gKTyB76CYUB5nJVyzgxnUT0CriftpEdA=; b=Adxe+xgYOoKIHTxzFe5lShU+QKKZ0kJJdIgFmNFBboipnFukfKF0rq8bEd+Fn5LrErRBUUyeiEYyqgE6fMA/AIac4GPH8hxOC7gFLfphSnAeZAvqeG1wNJYWI//CRgRkfHTfdxiXjjSDfHKNqEN+7R9bMwtmZdBTGGt59bmLD3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611076966904915.569540021847; Tue, 19 Jan 2021 09:22:46 -0800 (PST) Received: from localhost ([::1]:50790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1uiL-0002JF-QA for importer@patchew.org; Tue, 19 Jan 2021 12:22:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1uOY-0008WM-Pr; Tue, 19 Jan 2021 12:02:18 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1uOS-0003IS-W0; Tue, 19 Jan 2021 12:02:18 -0500 Received: by mail-pj1-x1036.google.com with SMTP id x20so265902pjh.3; Tue, 19 Jan 2021 09:02:11 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id m4sm19396001pgv.16.2021.01.19.09.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 09:02:10 -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=5ZLkaxx2eM6gKTyB76CYUB5nJVyzgxnUT0CriftpEdA=; b=KaVqHqpf5ZwAEsGLtaBJHNwd25WqqncSdk/1SaJ5JdxN6RBJ9EH/SAgDkC3kAhF/ZI 2K29n9/dTu4oD1ycnnY0wDV5qerW/lWKrBaXeWDOgXSYsOJKrAP7JSkcjNdwuCZ9mjE+ 1LuW8sNnCbcc3Na43f7g3PFpxbGAFLQ+GRpnHbexp21GBa2dYN0RO77WbCbVB81PBZzG tdYDda37l8uIBxBAUUF8Xp6zTrUkcI7drkHdbNGLgYBPZNuIeMyPqyG88darbn5hbB9c 7VpRe4yODg8Zl/AU/PlZi1UYnlIFgM4+Yf5MGjAkeeR8W2Jo1TMDEp/xsEQv6tzAtiPQ UIDQ== 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=5ZLkaxx2eM6gKTyB76CYUB5nJVyzgxnUT0CriftpEdA=; b=rDn3wAHwu+K82WFeHbRp+tEM8J8x1WKEXDOPLUTuI8z5CX0QYlAEZ5ZQlrWMUos1jw dIJXhU7qhgeFp2KjSw8Nvhx2JSPBLTSdoMkwIP8BDvKFg8uZmc0z6bcf6mOwFnXqjY5L l2oP+/TH/MNhh79NNM8YD6Lz4E9G8yAQwyHL3lsBCVIKpxydpP8nD3D0UGoQQECBmrEB BMPUr9cB+OQak0ISD9XS2vB0GsaR9mE0KvGqgpGJ/R4SOoQlkLU6QLxbKo28MhozQilN /F97nsN6tLd7R4BSiz8beMu/iaE17r9nsEd2R3aGgC1f/A+o7+WELOSFm5WyhSjlw7S6 hNnw== X-Gm-Message-State: AOAM533g8Xnxo2dnL2Z2q169aq7yL0MZnJulrOMOS35wOkq/9tLukwcj fcwmuuukwSiK7KEw9/6nLleEPlfdzCXFHA== X-Google-Smtp-Source: ABdhPJybphbRSE+OWihoSFQwZ51ltAaCfWhmo1GLXful/fmYP2LnLYsQf0KM/gxTi0VErUgaZrpmjg== X-Received: by 2002:a17:902:e881:b029:de:593d:82ca with SMTP id w1-20020a170902e881b02900de593d82camr5733568plg.82.1611075730603; Tue, 19 Jan 2021 09:02:10 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [RFC PATCH V3 6/8] hw/block/nvme: support for shared namespace in subsystem Date: Wed, 20 Jan 2021 02:01:45 +0900 Message-Id: <20210119170147.19657-7-minwoo.im.dev@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210119170147.19657-1-minwoo.im.dev@gmail.com> References: <20210119170147.19657-1-minwoo.im.dev@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=minwoo.im.dev@gmail.com; helo=mail-pj1-x1036.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" nvme-ns device is registered to a nvme controller device during the initialization in nvme_register_namespace() in case that 'bus' property is given which means it's mapped to a single controller. This patch introduced a new property 'subsys' just like the controller device instance did to map a namespace to a NVMe subsystem. If 'subsys' property is given to the nvme-ns device, it will belong to the specified subsystem and will be attached to all controllers in that subsystem by enabling shared namespace capability in NMIC(Namespace Multi-path I/O and Namespace Capabilities) in Identify Namespace. Usage: -device nvme-subsys,id=3Dsubsys0 -device nvme,serial=3Dfoo,id=3Dnvme0,subsys=3Dsubsys0 -device nvme,serial=3Dbar,id=3Dnvme1,subsys=3Dsubsys0 -device nvme,serial=3Dbaz,id=3Dnvme2,subsys=3Dsubsys0 -device nvme-ns,id=3Dns1,drive=3D,nsid=3D1,subsys=3Dsubsys0 # Shared -device nvme-ns,id=3Dns2,drive=3D,nsid=3D2,bus=3Dnvme2 # Non-s= hared In the above example, 'ns1' will be shared to 'nvme0' and 'nvme1' in the same subsystem. On the other hand, 'ns2' will be attached to the 'nvme2' only as a private namespace in that subsystem. All the namespace with 'subsys' parameter will attach all controllers in the subsystem to the namespace by default. Signed-off-by: Minwoo Im --- hw/block/nvme-ns.c | 23 ++++++++++++++++++----- hw/block/nvme-ns.h | 7 +++++++ hw/block/nvme-subsys.c | 25 +++++++++++++++++++++++++ hw/block/nvme-subsys.h | 3 +++ hw/block/nvme.c | 10 +++++++++- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index c8b75fa02138..073f65e49cac 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -63,6 +63,10 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) =20 id_ns->npda =3D id_ns->npdg =3D npdg - 1; =20 + if (nvme_ns_shared(ns)) { + id_ns->nmic |=3D NVME_NMIC_NS_SHARED; + } + return 0; } =20 @@ -358,16 +362,25 @@ static void nvme_ns_realize(DeviceState *dev, Error *= *errp) return; } =20 - if (nvme_register_namespace(n, ns, errp)) { - error_propagate_prepend(errp, local_err, - "could not register namespace: "); - return; + if (ns->subsys) { + if (nvme_subsys_register_ns(ns, errp)) { + error_propagate_prepend(errp, local_err, + "could not setup namespace to subsys: = "); + return; + } + } else { + if (nvme_register_namespace(n, ns, errp)) { + error_propagate_prepend(errp, local_err, + "could not register namespace: "); + return; + } } - } =20 static Property nvme_ns_props[] =3D { DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf), + DEFINE_PROP_LINK("subsys", NvmeNamespace, subsys, TYPE_NVME_SUBSYS, + NvmeSubsystem *), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid), DEFINE_PROP_BOOL("zoned", NvmeNamespace, params.zoned, false), diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 293ac990e3f6..929e78861903 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -47,6 +47,8 @@ typedef struct NvmeNamespace { const uint32_t *iocs; uint8_t csi; =20 + NvmeSubsystem *subsys; + NvmeIdNsZoned *id_ns_zoned; NvmeZone *zone_array; QTAILQ_HEAD(, NvmeZone) exp_open_zones; @@ -77,6 +79,11 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns) return -1; } =20 +static inline bool nvme_ns_shared(NvmeNamespace *ns) +{ + return !!ns->subsys; +} + static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns) { NvmeIdNs *id_ns =3D &ns->id_ns; diff --git a/hw/block/nvme-subsys.c b/hw/block/nvme-subsys.c index a01003136b12..e7efdcae7d0d 100644 --- a/hw/block/nvme-subsys.c +++ b/hw/block/nvme-subsys.c @@ -43,6 +43,31 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp) return cntlid; } =20 +int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp) +{ + NvmeSubsystem *subsys =3D ns->subsys; + NvmeCtrl *n; + int i; + + if (subsys->namespaces[nvme_nsid(ns)]) { + error_setg(errp, "namespace %d already registerd to subsy %s", + nvme_nsid(ns), subsys->parent_obj.id); + return -1; + } + + subsys->namespaces[nvme_nsid(ns)] =3D ns; + + for (i =3D 0; i < ARRAY_SIZE(subsys->ctrls); i++) { + n =3D subsys->ctrls[i]; + + if (n && nvme_register_namespace(n, ns, errp)) { + return -1; + } + } + + return 0; +} + static void nvme_subsys_setup(NvmeSubsystem *subsys) { char *subnqn; diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 4eba50d96a1d..ccf6a71398d3 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -14,6 +14,7 @@ OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) =20 #define NVME_SUBSYS_MAX_CTRLS 32 +#define NVME_SUBSYS_MAX_NAMESPACES 32 =20 typedef struct NvmeCtrl NvmeCtrl; typedef struct NvmeNamespace NvmeNamespace; @@ -22,8 +23,10 @@ typedef struct NvmeSubsystem { uint8_t subnqn[256]; =20 NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; + NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES]; } NvmeSubsystem; =20 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); +int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp); =20 #endif /* NVME_SUBSYS_H */ diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 9f8a739fcd8f..06bccf1b9e9e 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -25,7 +25,8 @@ * mdts=3D,zoned.append_size_limit=3D \ * ,subsys=3D \ * -device nvme-ns,drive=3D,bus=3D,nsid=3D,\ - * zoned=3D + * zoned=3D, \ + * subsys=3D * -device nvme-subsys,id=3D * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at @@ -69,6 +70,13 @@ * data size being in effect. By setting this property to 0, users can m= ake * ZASL to be equal to MDTS. This property only affects zoned namespaces. * + * nvme namespace device parameters + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * - `subsys` + * NVM Subsystem device. If given, this namespace will be attached to a= ll + * controllers in the subsystem. Otherwise, `bus` must be given to attach + * this namespace to a specified single controller as a non-shared names= pace. + * * Setting `zoned` to true selects Zoned Command Set at the namespace. * In this case, the following namespace properties are available to confi= gure * zoned operation: --=20 2.17.1