From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "John Snow" <jsnow@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Aarushi Mehta" <mehta.aaru20@gmail.com>,
"Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
qemu-block@nongnu.org, "Julia Suvorova" <jusual@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Alistair Francis" <alistair@alistair23.me>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Hanna Reitz" <hreitz@redhat.com>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>
Subject: [PULL 4/5] hw/core/qdev.c: add qdev_get_human_name()
Date: Tue, 30 Jan 2024 16:51:33 -0500 [thread overview]
Message-ID: <20240130215134.346557-5-stefanha@redhat.com> (raw)
In-Reply-To: <20240130215134.346557-1-stefanha@redhat.com>
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Add a simple method to return some kind of human readable identifier for
use in error messages.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-id: 8b566bfced98ae44be1fcc1f8e7215f0c3393aa1.1706598705.git.manos.pitsidianakis@linaro.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/hw/qdev-core.h | 14 ++++++++++++++
hw/core/qdev.c | 8 ++++++++
2 files changed, 22 insertions(+)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 151d968238..66338f479f 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -993,6 +993,20 @@ const char *qdev_fw_name(DeviceState *dev);
void qdev_assert_realized_properly(void);
Object *qdev_get_machine(void);
+/**
+ * qdev_get_human_name() - Return a human-readable name for a device
+ * @dev: The device. Must be a valid and non-NULL pointer.
+ *
+ * .. note::
+ * This function is intended for user friendly error messages.
+ *
+ * Returns: A newly allocated string containing the device id if not null,
+ * else the object canonical path.
+ *
+ * Use g_free() to free it.
+ */
+char *qdev_get_human_name(DeviceState *dev);
+
/* FIXME: make this a link<> */
bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp);
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 43d863b0c5..c68d0f7c51 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -879,6 +879,14 @@ Object *qdev_get_machine(void)
return dev;
}
+char *qdev_get_human_name(DeviceState *dev)
+{
+ g_assert(dev != NULL);
+
+ return dev->id ?
+ g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev));
+}
+
static MachineInitPhase machine_phase;
bool phase_check(MachineInitPhase phase)
--
2.43.0
next prev parent reply other threads:[~2024-01-30 21:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 21:51 [PULL 0/5] Block patches Stefan Hajnoczi
2024-01-30 21:51 ` [PULL 1/5] block/io_uring: improve error message when init fails Stefan Hajnoczi
2024-01-30 21:51 ` [PULL 2/5] block/blkio: Make s->mem_region_alignment be 64 bits Stefan Hajnoczi
2024-01-30 21:51 ` [PULL 3/5] pflash: fix sectors vs bytes confusion in blk_pread_nonzeroes() Stefan Hajnoczi
2024-01-30 21:51 ` Stefan Hajnoczi [this message]
2024-01-30 21:51 ` [PULL 5/5] hw/block/block.c: improve confusing blk_check_size_and_read_all() error Stefan Hajnoczi
2024-02-01 10:55 ` [PULL 0/5] Block patches Peter Maydell
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=20240130215134.346557-5-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=alistair@alistair23.me \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=jusual@redhat.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=mehta.aaru20@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
/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).