qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Zhenwei Pi" <pizhenwei@bytedance.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Gonglei (Arei)" <arei.gonglei@huawei.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Peter Xu" <peterx@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	"Eduardo Habkost" <eduardo@habkost.net>
Subject: [PATCH v4 3/8] qdev: Add machine_get_container()
Date: Thu,  2 Jan 2025 22:17:55 +0100	[thread overview]
Message-ID: <20250102211800.79235-4-philmd@linaro.org> (raw)
In-Reply-To: <20250102211800.79235-1-philmd@linaro.org>

From: Peter Xu <peterx@redhat.com>

Add a helper to fetch machine containers.  Add some sanity check around.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-ID: <20241121192202.4155849-10-peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/qdev-core.h | 10 ++++++++++
 hw/core/qdev.c         | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index b83b1439968..2434065bad2 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -1037,6 +1037,16 @@ Object *qdev_get_machine(void);
  */
 Object *qdev_create_fake_machine(void);
 
+/**
+ * machine_get_container:
+ * @name: The name of container to lookup
+ *
+ * Get a container of the machine (QOM path "/machine/NAME").
+ *
+ * Returns: the machine container object.
+ */
+Object *machine_get_container(const char *name);
+
 /**
  * qdev_get_human_name() - Return a human-readable name for a device
  * @dev: The device. Must be a valid and non-NULL pointer.
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index bc5b60212a7..9973e029ffa 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -829,6 +829,17 @@ Object *qdev_get_machine(void)
     return dev;
 }
 
+Object *machine_get_container(const char *name)
+{
+    Object *container, *machine;
+
+    machine = qdev_get_machine();
+    container = object_resolve_path_component(machine, name);
+    assert(object_dynamic_cast(container, TYPE_CONTAINER));
+
+    return container;
+}
+
 char *qdev_get_human_name(DeviceState *dev)
 {
     g_assert(dev != NULL);
-- 
2.47.1



  parent reply	other threads:[~2025-01-02 21:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02 21:17 [PATCH v4 0/8] QOM: container_get() removal Philippe Mathieu-Daudé
2025-01-02 21:17 ` [PATCH v4 1/8] qdev: Implement qdev_create_fake_machine() for user emulation Philippe Mathieu-Daudé
2025-01-02 22:05   ` Peter Xu
2025-01-03 14:24   ` Richard Henderson
2025-01-03 14:37     ` Philippe Mathieu-Daudé
2025-01-02 21:17 ` [PATCH v4 2/8] qdev: Make qdev_get_machine() not use container_get() Philippe Mathieu-Daudé
2025-01-03 14:26   ` Richard Henderson
2025-01-02 21:17 ` Philippe Mathieu-Daudé [this message]
2025-01-03 14:27   ` [PATCH v4 3/8] qdev: Add machine_get_container() Richard Henderson
2025-01-02 21:17 ` [PATCH v4 4/8] qdev: Use machine_get_container() Philippe Mathieu-Daudé
2025-01-03 14:29   ` Richard Henderson
2025-01-02 21:17 ` [PATCH v4 5/8] qom: Add object_get_container() Philippe Mathieu-Daudé
2025-01-03 14:29   ` Richard Henderson
2025-01-02 21:17 ` [PATCH v4 6/8] qom: Use object_get_container() Philippe Mathieu-Daudé
2025-01-03 14:30   ` Richard Henderson
2025-01-02 21:17 ` [PATCH v4 7/8] qom: Remove container_get() Philippe Mathieu-Daudé
2025-01-03 14:31   ` Richard Henderson
2025-01-02 21:18 ` [PATCH v4 8/8] system: Inline machine_containers[] in qemu_create_machine_containers() Philippe Mathieu-Daudé
2025-01-03 14:32   ` Richard Henderson
2025-01-09 14:40 ` [PATCH v4 0/8] QOM: container_get() removal Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250102211800.79235-4-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=arei.gonglei@huawei.com \
    --cc=berrange@redhat.com \
    --cc=david@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=fam@euphon.net \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pizhenwei@bytedance.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).