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=1611077200; cv=none; d=zohomail.com; s=zohoarc; b=kL/hvMaXcAREBxLKxdppwA28U6b8kdJNURkW6qQA4TFv5NOmJ+W8J7MgKptr+vbhYBCxl8Wrr6cqjR+CmAME0il8an3Ky29Z8uag/CfwYZy6DmgnuoW8BvpOcgnnT2bc3iCfyqGskleUOhg+bYQxXO7OsrdW5aaRmppFwSnNkYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611077200; 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=0m1jGuGz0yvQKHqdKo33hE6rgLKvgF6GneF5gBBFRpE=; b=mBxzmjWm29Za6ASltD+wH552l5aiqoHwyD0bq0YPMvwzFu5R6deyioRPS9ZoKT+KAbz9+PZxHeT8IMbN/Y/rX6SBzw5RtXzeTxTfqzvf61fZBDlYAEhFqYOFCxPIo7rwqWtPerbrzXrfqDVQZ0BbOwARPImy84WS7nwJxz/UxRE= 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 1611077200636380.10351870189095; Tue, 19 Jan 2021 09:26:40 -0800 (PST) Received: from localhost ([::1]:59646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1um7-00060S-KO for importer@patchew.org; Tue, 19 Jan 2021 12:26:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1uOI-0007wQ-Ck; Tue, 19 Jan 2021 12:02:02 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:36404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1uOG-0003FN-CE; Tue, 19 Jan 2021 12:02:02 -0500 Received: by mail-pj1-x102e.google.com with SMTP id l23so270972pjg.1; Tue, 19 Jan 2021 09:01:59 -0800 (PST) Received: from localhost.localdomain ([211.108.35.36]) by smtp.gmail.com with ESMTPSA id m4sm19396001pgv.16.2021.01.19.09.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 09:01:57 -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=0m1jGuGz0yvQKHqdKo33hE6rgLKvgF6GneF5gBBFRpE=; b=EGLLD2wjRFEWq6n0uMlG2mDKx/03sQrRQYFtSoHY4YRu8c9KmWgo/9APURbmwRH7KE NiCp3HiPf934Ecn7y0KFQnJYdYRLvsFYTCN1jdywbp4NX8ahRK9OFuUGbuKppd2A+emn yynHZdWWfhbdG3xm18APovylwB9qppYGm6NHyJtIYBVnG5mCix8tn8pqpQJuwtCmiJ2G h13twhCEfcXgnVw0/bmSQLzBBd9PSDg7MRsByK9qVbPKWWSgcpLonirfOtbqav8S7IEf rHWuvuuesywhlg9N58OtGb2SHBevi6jL86BmDrmLVg6nX5U8VZi+olUDQ6Ti9ImMJk+Z xw/A== 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=0m1jGuGz0yvQKHqdKo33hE6rgLKvgF6GneF5gBBFRpE=; b=rJkmpHIz39J34qwJ7qm7T4TzxlE25VWGFMwOaSxR4SIUfp93ixAnDlg5lnEbkTuAtt mU77mLHKI9sqyOqsbMjlnPkfttxkY1mDOpaF/DR0VtVXuVCCa0FuYPI5uMY53886AsYE NxTUZqDU69JhN0xheywFgcFCjBbts/j7TzIXaHhrz9Nrz8yPBSsH/sPd6sNiu0fhyG0R YvqLITfxhV4hZlpfuz85GIRkIOoLHErnL/N4cD0DI2qo9gWGKzVN+8mhrtsPDxvYyRVM NgOGi2TF7utuzpY+scF7Z8pmUC2b4lr3fLjKqfJhDTVc0aI+lq82RlLTMkuZuwBICcR7 XobA== X-Gm-Message-State: AOAM532XqnA8+S1VC+A665kmTXm5rzNkr5nJZNLaJAuKFBC7iMJKqGzA 46VF7lAFLzSzA/I9i5Gv4pr4IRF9AhDICw== X-Google-Smtp-Source: ABdhPJyn3f55V9uFR4RvuGp+Z3O13qPtm1xCzzGZNT4+Y+FlcJSF0lc/8ShoEhJYbeVY6MjZzOdkYg== X-Received: by 2002:a17:902:6b84:b029:dc:3423:a24a with SMTP id p4-20020a1709026b84b02900dc3423a24amr5483729plk.31.1611075718034; Tue, 19 Jan 2021 09:01:58 -0800 (PST) From: Minwoo Im To: qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [RFC PATCH V3 1/8] hw/block/nvme: introduce nvme-subsys device Date: Wed, 20 Jan 2021 02:01:40 +0900 Message-Id: <20210119170147.19657-2-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::102e; envelope-from=minwoo.im.dev@gmail.com; helo=mail-pj1-x102e.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" To support multi-path in QEMU NVMe device model, We need to have NVMe subsystem hierarchy to map controllers and namespaces to a NVMe subsystem. This patch introduced a simple nvme-subsys device model. The subsystem will be prepared with subsystem NQN with provided in nvme-subsys device: ex) -device nvme-subsys,id=3Dsubsys0: nqn.2019-08.org.qemu:subsys0 Signed-off-by: Minwoo Im --- hw/block/meson.build | 2 +- hw/block/nvme-subsys.c | 63 ++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme-subsys.h | 25 +++++++++++++++++ hw/block/nvme.c | 3 ++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 hw/block/nvme-subsys.c create mode 100644 hw/block/nvme-subsys.h diff --git a/hw/block/meson.build b/hw/block/meson.build index 602ca6c8541d..83ea2d37978d 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -13,7 +13,7 @@ softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files(= 'm25p80.c')) softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c')) softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c')) softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('tc58128.c')) -softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('nvme.c', 'nvme-ns.= c')) +softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('nvme.c', 'nvme-ns.= c', 'nvme-subsys.c')) =20 specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c')) diff --git a/hw/block/nvme-subsys.c b/hw/block/nvme-subsys.c new file mode 100644 index 000000000000..f1dc71d588d9 --- /dev/null +++ b/hw/block/nvme-subsys.c @@ -0,0 +1,63 @@ +/* + * QEMU NVM Express Subsystem: nvme-subsys + * + * Copyright (c) 2021 Minwoo Im + * + * This code is licensed under the GNU GPL v2. Refer COPYING. + */ + +#include "qemu/units.h" +#include "qemu/osdep.h" +#include "qemu/uuid.h" +#include "qemu/iov.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" +#include "hw/block/block.h" +#include "block/aio.h" +#include "block/accounting.h" +#include "sysemu/sysemu.h" +#include "hw/pci/pci.h" +#include "nvme.h" +#include "nvme-subsys.h" + +static void nvme_subsys_setup(NvmeSubsystem *subsys) +{ + char *subnqn; + + subnqn =3D g_strdup_printf("nqn.2019-08.org.qemu:%s", subsys->parent_o= bj.id); + strpadcpy((char *)subsys->subnqn, sizeof(subsys->subnqn), subnqn, '\0'= ); + g_free(subnqn); +} + +static void nvme_subsys_realize(DeviceState *dev, Error **errp) +{ + NvmeSubsystem *subsys =3D NVME_SUBSYS(dev); + + nvme_subsys_setup(subsys); +} + +static void nvme_subsys_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + + dc->realize =3D nvme_subsys_realize; + dc->desc =3D "Virtual NVMe subsystem"; +} + +static const TypeInfo nvme_subsys_info =3D { + .name =3D TYPE_NVME_SUBSYS, + .parent =3D TYPE_DEVICE, + .class_init =3D nvme_subsys_class_init, + .instance_size =3D sizeof(NvmeSubsystem), +}; + +static void nvme_subsys_register_types(void) +{ + type_register_static(&nvme_subsys_info); +} + +type_init(nvme_subsys_register_types) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h new file mode 100644 index 000000000000..40f06a4c7db0 --- /dev/null +++ b/hw/block/nvme-subsys.h @@ -0,0 +1,25 @@ +/* + * QEMU NVM Express Subsystem: nvme-subsys + * + * Copyright (c) 2021 Minwoo Im + * + * This code is licensed under the GNU GPL v2. Refer COPYING. + */ + +#ifndef NVME_SUBSYS_H +#define NVME_SUBSYS_H + +#define TYPE_NVME_SUBSYS "nvme-subsys" +#define NVME_SUBSYS(obj) \ + OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) + +#define NVME_SUBSYS_MAX_CTRLS 32 + +typedef struct NvmeCtrl NvmeCtrl; +typedef struct NvmeNamespace NvmeNamespace; +typedef struct NvmeSubsystem { + DeviceState parent_obj; + uint8_t subnqn[256]; +} NvmeSubsystem; + +#endif /* NVME_SUBSYS_H */ diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 309c26db8ff7..4644937a5c50 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -25,6 +25,7 @@ * mdts=3D,zoned.append_size_limit=3D \ * -device nvme-ns,drive=3D,bus=3D,nsid=3D,\ * zoned=3D + * -device nvme-subsys,id=3D * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at * offset 0 in BAR2 and supports only WDS, RDS and SQS for now. @@ -37,6 +38,8 @@ * -object memory-backend-file,id=3D,share=3Don,mem-path=3D, \ * size=3D .... -device nvme,...,pmrdev=3D * + * To place controller(s) and namespace(s) to a subsystem, then provide + * nvme-subsys device as above. * * nvme device parameters * ~~~~~~~~~~~~~~~~~~~~~~ --=20 2.17.1