From 956ef499902b09aa8a3e70791455ccf45645032d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 30 Jan 2024 09:30:31 +0200 Subject: hw/core/qdev.c: add qdev_get_human_name() Add a simple method to return some kind of human readable identifier for use in error messages. Reviewed-by: Stefan Hajnoczi Signed-off-by: Manos Pitsidianakis Message-id: 8b566bfced98ae44be1fcc1f8e7215f0c3393aa1.1706598705.git.manos.pitsidianakis@linaro.org Signed-off-by: Stefan Hajnoczi --- include/hw/qdev-core.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/hw') diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 151d968..66338f4 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); -- cgit v1.1 From 954b33daee83fe79293fd81c2f7371db48e7d6bd Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 30 Jan 2024 09:30:32 +0200 Subject: hw/block/block.c: improve confusing blk_check_size_and_read_all() error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In cases where a device tries to read more bytes than the block device contains, the error is vague: "device requires X bytes, block backend provides Y bytes". This patch changes the errors of this function to include the block backend name, the device id and device type name where appropriate. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Manos Pitsidianakis Message-id: 7260eadff22c08457740117c1bb7bd2b4353acb9.1706598705.git.manos.pitsidianakis@linaro.org Signed-off-by: Stefan Hajnoczi --- include/hw/block/block.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/hw') diff --git a/include/hw/block/block.h b/include/hw/block/block.h index 15fff664..de3946a 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -88,8 +88,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) /* Backend access helpers */ -bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size, - Error **errp); +bool blk_check_size_and_read_all(BlockBackend *blk, DeviceState *dev, + void *buf, hwaddr size, Error **errp); /* Configuration helpers */ -- cgit v1.1