* [PULL 01/17] hw/core/loader: Make load_elf_hdr() return bool, simplify caller
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 02/17] hw/nvram/xlnx-bbram: More idiomatic and simpler error reporting Markus Armbruster
` (15 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Vladimir Sementsov-Ogievskiy, Peter Xu,
Daniel Henrique Barboza, Zhao Liu
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-2-armbru@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
include/hw/core/loader.h | 4 +++-
hw/arm/boot.c | 6 +-----
hw/core/loader.c | 8 ++++++--
hw/riscv/spike.c | 10 +---------
4 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/include/hw/core/loader.h b/include/hw/core/loader.h
index d035e72748..6f91703503 100644
--- a/include/hw/core/loader.h
+++ b/include/hw/core/loader.h
@@ -188,8 +188,10 @@ ssize_t load_elf(const char *filename,
*
* Inspect an ELF file's header. Read its full header contents into a
* buffer and/or determine if the ELF is 64bit.
+ *
+ * Returns true on success, false on failure.
*/
-void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
+bool load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
ssize_t load_aout(const char *filename, hwaddr addr, int max_sz,
bool big_endian, hwaddr target_page_size);
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 0ba3adaf81..e22609de93 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -766,16 +766,12 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
int data_swab = 0;
int elf_data_order;
ssize_t ret;
- Error *err = NULL;
-
- load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err);
- if (err) {
+ if (!load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, NULL)) {
/*
* If the file is not an ELF file we silently return.
* The caller will fall back to try other formats.
*/
- error_free(err);
return -1;
}
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 8252616fdd..89d67d2760 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -364,8 +364,9 @@ const char *load_elf_strerror(ssize_t error)
}
}
-void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp)
+bool load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp)
{
+ bool ok = false;
int fd;
uint8_t e_ident_local[EI_NIDENT];
uint8_t *e_ident;
@@ -380,7 +381,7 @@ void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp)
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
error_setg_errno(errp, errno, "Failed to open file: %s", filename);
- return;
+ return false;
}
if (read(fd, hdr, EI_NIDENT) != EI_NIDENT) {
error_setg_errno(errp, errno, "Failed to read file: %s", filename);
@@ -415,8 +416,11 @@ void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp)
off += br;
}
+ ok = true;
+
fail:
close(fd);
+ return ok;
}
/* return < 0 if error, otherwise the number of bytes loaded in memory */
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index 1493b928da..35c696f891 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -180,15 +180,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,
static bool spike_test_elf_image(char *filename)
{
- Error *err = NULL;
-
- load_elf_hdr(filename, NULL, NULL, &err);
- if (err) {
- error_free(err);
- return false;
- } else {
- return true;
- }
+ return load_elf_hdr(filename, NULL, NULL, NULL);
}
static void spike_board_init(MachineState *machine)
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 02/17] hw/nvram/xlnx-bbram: More idiomatic and simpler error reporting
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
2026-01-07 12:43 ` [PULL 01/17] hw/core/loader: Make load_elf_hdr() return bool, simplify caller Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 03/17] nbd/client-connection: Replace error_propagate() by assignment Markus Armbruster
` (14 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Vladimir Sementsov-Ogievskiy, Peter Xu,
Luc Michel, Zhao Liu
bbram_bdrv_error() interpolates a "detail" string into a template with
error_setg_errno(), then reports the result with error_report().
Produces error messages with an unwanted '.':
BLK-NAME: BBRAM backstore DETAIL failed.: STERROR
Replace both calls of bbram_bdrv_error() by straightforward
error_report(), and drop the function. This is less code, easier to
read, and the error message is more greppable.
Also delete the unwanted '.'.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-3-armbru@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Luc Michel <luc.michel@amd.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/nvram/xlnx-bbram.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c
index 60ede7e40f..edfb592a5e 100644
--- a/hw/nvram/xlnx-bbram.c
+++ b/hw/nvram/xlnx-bbram.c
@@ -88,18 +88,6 @@ static bool bbram_pgm_enabled(XlnxBBRam *s)
return ARRAY_FIELD_EX32(s->regs, BBRAM_STATUS, PGM_MODE) != 0;
}
-static void bbram_bdrv_error(XlnxBBRam *s, int rc, gchar *detail)
-{
- Error *errp = NULL;
-
- error_setg_errno(&errp, -rc, "%s: BBRAM backstore %s failed.",
- blk_name(s->blk), detail);
- error_report("%s", error_get_pretty(errp));
- error_free(errp);
-
- g_free(detail);
-}
-
static void bbram_bdrv_read(XlnxBBRam *s, Error **errp)
{
uint32_t *ram = &s->regs[R_BBRAM_0];
@@ -162,7 +150,8 @@ static void bbram_bdrv_sync(XlnxBBRam *s, uint64_t hwaddr)
offset = hwaddr - A_BBRAM_0;
rc = blk_pwrite(s->blk, offset, 4, &le32, 0);
if (rc < 0) {
- bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offset));
+ error_report("%s: BBRAM backstore write to offset %u failed: %s",
+ blk_name(s->blk), offset, strerror(-rc));
}
}
@@ -178,7 +167,8 @@ static void bbram_bdrv_zero(XlnxBBRam *s)
rc = blk_make_zero(s->blk, 0);
if (rc < 0) {
- bbram_bdrv_error(s, rc, g_strdup("zeroizing"));
+ error_report("%s: BBRAM backstore zeroizing failed: %s",
+ blk_name(s->blk), strerror(-rc));
}
/* Restore bbram8 if it is non-zero */
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 03/17] nbd/client-connection: Replace error_propagate() by assignment
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
2026-01-07 12:43 ` [PULL 01/17] hw/core/loader: Make load_elf_hdr() return bool, simplify caller Markus Armbruster
2026-01-07 12:43 ` [PULL 02/17] hw/nvram/xlnx-bbram: More idiomatic and simpler error reporting Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 04/17] error: error_free(NULL) is safe, drop unnecessary conditionals Markus Armbruster
` (13 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Vladimir Sementsov-Ogievskiy, Peter Xu,
Zhao Liu
connect_thread_func() sets a variable to null, then error_propagate()s
an Error * to it. This is a roundabout way to assign the Error * to
it, so replace it by just that.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-4-armbru@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
nbd/client-connection.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/nbd/client-connection.c b/nbd/client-connection.c
index 79ea97e4cc..6a4f080717 100644
--- a/nbd/client-connection.c
+++ b/nbd/client-connection.c
@@ -207,8 +207,7 @@ static void *connect_thread_func(void *opaque)
qemu_mutex_lock(&conn->mutex);
error_free(conn->err);
- conn->err = NULL;
- error_propagate(&conn->err, local_err);
+ conn->err = local_err;
if (ret < 0) {
object_unref(OBJECT(conn->sioc));
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 04/17] error: error_free(NULL) is safe, drop unnecessary conditionals
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (2 preceding siblings ...)
2026-01-07 12:43 ` [PULL 03/17] nbd/client-connection: Replace error_propagate() by assignment Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 05/17] error: Consistently name Error * objects err, and not errp Markus Armbruster
` (12 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Vladimir Sementsov-Ogievskiy, Peter Xu,
Zhao Liu
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-5-armbru@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/acpi/pcihp.c | 4 +---
io/channel-websock.c | 4 +---
io/task.c | 4 +---
migration/migration.c | 6 ++----
tests/unit/test-smp-parse.c | 5 +----
5 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 4922bbc778..87162ff2c0 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -62,9 +62,7 @@ static int acpi_pcihp_get_bsel(PCIBus *bus)
&local_err);
if (local_err || bsel >= ACPI_PCIHP_MAX_HOTPLUG_BUS) {
- if (local_err) {
- error_free(local_err);
- }
+ error_free(local_err);
return -1;
} else {
return bsel;
diff --git a/io/channel-websock.c b/io/channel-websock.c
index cb4dafdebb..d0929ba232 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -932,9 +932,7 @@ static void qio_channel_websock_finalize(Object *obj)
if (ioc->io_tag) {
g_source_remove(ioc->io_tag);
}
- if (ioc->io_err) {
- error_free(ioc->io_err);
- }
+ error_free(ioc->io_err);
object_unref(OBJECT(ioc->master));
}
diff --git a/io/task.c b/io/task.c
index 451f26f8b4..da79d31782 100644
--- a/io/task.c
+++ b/io/task.c
@@ -91,9 +91,7 @@ static void qio_task_free(QIOTask *task)
if (task->destroyResult) {
task->destroyResult(task->result);
}
- if (task->err) {
- error_free(task->err);
- }
+ error_free(task->err);
object_unref(task->source);
qemu_mutex_unlock(&task->thread_lock);
diff --git a/migration/migration.c b/migration/migration.c
index 9d1bf5d276..1c34d8d432 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1568,10 +1568,8 @@ bool migrate_has_error(MigrationState *s)
static void migrate_error_free(MigrationState *s)
{
QEMU_LOCK_GUARD(&s->error_mutex);
- if (s->error) {
- error_free(s->error);
- s->error = NULL;
- }
+ error_free(s->error);
+ s->error = NULL;
}
static void migration_connect_error_propagate(MigrationState *s, Error *error)
diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
index 28ea9158e7..1b6450e7d8 100644
--- a/tests/unit/test-smp-parse.c
+++ b/tests/unit/test-smp-parse.c
@@ -875,10 +875,7 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config,
config_str, expect_err, output_topo_str);
end:
- if (err != NULL) {
- error_free(err);
- }
-
+ error_free(err);
abort();
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 05/17] error: Consistently name Error * objects err, and not errp
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (3 preceding siblings ...)
2026-01-07 12:43 ` [PULL 04/17] error: error_free(NULL) is safe, drop unnecessary conditionals Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 06/17] error: Strip trailing '\n' from error string arguments (again) Markus Armbruster
` (11 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Zhao Liu
This touches code in xen_enable_tpm() that is obviously wrong. Since
I don't know how to fix it properly, I'm adding a FIXME there.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251119130855.105479-6-armbru@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
block/crypto.c | 8 ++++----
hw/acpi/ghes.c | 8 ++++----
hw/ppc/spapr.c | 16 ++++++++--------
hw/xen/xen-pvh-common.c | 13 ++++++++++---
nbd/common.c | 6 +++---
5 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index b97d027444..36abb7af46 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -938,14 +938,14 @@ static void GRAPH_RDLOCK
block_crypto_amend_cleanup(BlockDriverState *bs)
{
BlockCrypto *crypto = bs->opaque;
- Error *errp = NULL;
+ Error *err = NULL;
/* release exclusive read/write permissions to the underlying file */
crypto->updating_keys = false;
- bdrv_child_refresh_perms(bs, bs->file, &errp);
+ bdrv_child_refresh_perms(bs, bs->file, &err);
- if (errp) {
- error_report_err(errp);
+ if (err) {
+ error_report_err(err);
}
}
diff --git a/hw/acpi/ghes.c b/hw/acpi/ghes.c
index 365156dff9..5445dc11bd 100644
--- a/hw/acpi/ghes.c
+++ b/hw/acpi/ghes.c
@@ -564,7 +564,7 @@ int acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id,
const uint8_t guid[] =
UUID_LE(0xA5BC1114, 0x6F64, 0x4EDE, 0xB8, 0x63, 0x3E, 0x83, \
0xED, 0x7C, 0x83, 0xB1);
- Error *errp = NULL;
+ Error *err = NULL;
int data_length;
GArray *block;
@@ -584,12 +584,12 @@ int acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id,
acpi_ghes_build_append_mem_cper(block, physical_address);
/* Report the error */
- ghes_record_cper_errors(ags, block->data, block->len, source_id, &errp);
+ ghes_record_cper_errors(ags, block->data, block->len, source_id, &err);
g_array_free(block, true);
- if (errp) {
- error_report_err(errp);
+ if (err) {
+ error_report_err(err);
return -1;
}
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index bcf6aa560f..b3c5097bf8 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2848,7 +2848,7 @@ static void spapr_machine_init(MachineState *machine)
int i;
MemoryRegion *sysmem = get_system_memory();
long load_limit, fw_size;
- Error *errp = NULL;
+ Error *err = NULL;
NICInfo *nd;
if (!filename) {
@@ -2872,7 +2872,7 @@ static void spapr_machine_init(MachineState *machine)
/* Determine capabilities to run with */
spapr_caps_init(spapr);
- kvmppc_check_papr_resize_hpt(&errp);
+ kvmppc_check_papr_resize_hpt(&err);
if (spapr->resize_hpt == SPAPR_RESIZE_HPT_DEFAULT) {
/*
* If the user explicitly requested a mode we should either
@@ -2880,10 +2880,10 @@ static void spapr_machine_init(MachineState *machine)
* it's not set explicitly, we reset our mode to something
* that works
*/
- if (errp) {
+ if (err) {
spapr->resize_hpt = SPAPR_RESIZE_HPT_DISABLED;
- error_free(errp);
- errp = NULL;
+ error_free(err);
+ err = NULL;
} else {
spapr->resize_hpt = smc->resize_hpt_default;
}
@@ -2891,14 +2891,14 @@ static void spapr_machine_init(MachineState *machine)
assert(spapr->resize_hpt != SPAPR_RESIZE_HPT_DEFAULT);
- if ((spapr->resize_hpt != SPAPR_RESIZE_HPT_DISABLED) && errp) {
+ if ((spapr->resize_hpt != SPAPR_RESIZE_HPT_DISABLED) && err) {
/*
* User requested HPT resize, but this host can't supply it. Bail out
*/
- error_report_err(errp);
+ error_report_err(err);
exit(1);
}
- error_free(errp);
+ error_free(err);
spapr->rma_size = spapr_rma_size(spapr, &error_fatal);
diff --git a/hw/xen/xen-pvh-common.c b/hw/xen/xen-pvh-common.c
index f365222019..1381310fc7 100644
--- a/hw/xen/xen-pvh-common.c
+++ b/hw/xen/xen-pvh-common.c
@@ -101,7 +101,7 @@ static void xen_create_virtio_mmio_devices(XenPVHMachineState *s)
#ifdef CONFIG_TPM
static void xen_enable_tpm(XenPVHMachineState *s)
{
- Error *errp = NULL;
+ Error *err = NULL;
DeviceState *dev;
SysBusDevice *busdev;
@@ -111,8 +111,15 @@ static void xen_enable_tpm(XenPVHMachineState *s)
return;
}
dev = qdev_new(TYPE_TPM_TIS_SYSBUS);
- object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &errp);
- object_property_set_str(OBJECT(dev), "tpmdev", be->id, &errp);
+ /*
+ * FIXME This use of &err is is wrong. If both calls fail, the
+ * second will trip error_setv()'s assertion. If just one call
+ * fails, we leak an Error object. Setting the same property
+ * twice (first to a QOM path, then to an ID string) is almost
+ * certainly wrong, too.
+ */
+ object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &err);
+ object_property_set_str(OBJECT(dev), "tpmdev", be->id, &err);
busdev = SYS_BUS_DEVICE(dev);
sysbus_realize_and_unref(busdev, &error_fatal);
sysbus_mmio_map(busdev, 0, s->cfg.tpm.base);
diff --git a/nbd/common.c b/nbd/common.c
index 2a133a66c3..f43cbaa15b 100644
--- a/nbd/common.c
+++ b/nbd/common.c
@@ -282,10 +282,10 @@ void nbd_set_socket_send_buffer(QIOChannelSocket *sioc)
#ifdef UNIX_STREAM_SOCKET_SEND_BUFFER_SIZE
if (sioc->localAddr.ss_family == AF_UNIX) {
size_t size = UNIX_STREAM_SOCKET_SEND_BUFFER_SIZE;
- Error *errp = NULL;
+ Error *err = NULL;
- if (qio_channel_socket_set_send_buffer(sioc, size, &errp) < 0) {
- warn_report_err(errp);
+ if (qio_channel_socket_set_send_buffer(sioc, size, &err) < 0) {
+ warn_report_err(err);
}
}
#endif /* UNIX_STREAM_SOCKET_SEND_BUFFER_SIZE */
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 06/17] error: Strip trailing '\n' from error string arguments (again)
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (4 preceding siblings ...)
2026-01-07 12:43 ` [PULL 05/17] error: Consistently name Error * objects err, and not errp Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 07/17] ui: Convert to qemu_create() for simplicity and consistency Markus Armbruster
` (10 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Philippe Mathieu-Daudé
Tracked down with scripts/coccinelle/err-bad-newline.cocci.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-2-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/audio/es1370.c | 2 +-
ui/gtk.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 9873ffadab..566f93f1ea 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -228,7 +228,7 @@ static void print_sctl(uint32_t val)
#undef a
error_report("es1370: "
"%s p2_end_inc %d, p2_st_inc %d,"
- " r1_fmt %s, p2_fmt %s, p1_fmt %s\n",
+ " r1_fmt %s, p2_fmt %s, p1_fmt %s",
buf,
(val & SCTRL_P2ENDINC) >> SCTRL_SH_P2ENDINC,
(val & SCTRL_P2STINC) >> SCTRL_SH_P2STINC,
diff --git a/ui/gtk.c b/ui/gtk.c
index 48571bedbf..e83a366625 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1197,7 +1197,7 @@ static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch,
type = INPUT_MULTI_TOUCH_TYPE_END;
break;
default:
- warn_report("gtk: unexpected touch event type\n");
+ warn_report("gtk: unexpected touch event type");
return FALSE;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 07/17] ui: Convert to qemu_create() for simplicity and consistency
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (5 preceding siblings ...)
2026-01-07 12:43 ` [PULL 06/17] error: Strip trailing '\n' from error string arguments (again) Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 08/17] tap-solaris: Use error_setg_file_open() for better error messages Markus Armbruster
` (9 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson
The error message changes from
failed to open file 'FILENAME': REASON
to
Could not create 'FILENAME': REASON
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-4-armbru@redhat.com>
---
ui/ui-qmp-cmds.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/ui/ui-qmp-cmds.c b/ui/ui-qmp-cmds.c
index 74fa6c6ec5..b49b636152 100644
--- a/ui/ui-qmp-cmds.c
+++ b/ui/ui-qmp-cmds.c
@@ -369,10 +369,8 @@ qmp_screendump(const char *filename, const char *device,
}
image = pixman_image_ref(surface->image);
- fd = qemu_open_old(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+ fd = qemu_create(filename, O_WRONLY | O_TRUNC | O_BINARY, 0666, errp);
if (fd == -1) {
- error_setg(errp, "failed to open file '%s': %s", filename,
- strerror(errno));
return;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 08/17] tap-solaris: Use error_setg_file_open() for better error messages
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (6 preceding siblings ...)
2026-01-07 12:43 ` [PULL 07/17] ui: Convert to qemu_create() for simplicity and consistency Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 09/17] qga: " Markus Armbruster
` (8 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Dr. David Alan Gilbert,
Philippe Mathieu-Daudé
Error messages change from
Can't open /dev/ip (actually /dev/udp)
Can't open /dev/tap
Can't open /dev/tap (2)
to
Could not open '/dev/udp': REASON
Could not open '/dev/tap': REASON
where REASON is the value of strerror(errno).
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Message-ID: <20251121121438.1249498-5-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
net/tap-solaris.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 75397e6c54..faf7922ea8 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -87,13 +87,13 @@ static int tap_alloc(char *dev, size_t dev_size, Error **errp)
ip_fd = RETRY_ON_EINTR(open("/dev/udp", O_RDWR, 0));
if (ip_fd < 0) {
- error_setg(errp, "Can't open /dev/ip (actually /dev/udp)");
+ error_setg_file_open(errp, errno, "/dev/udp");
return -1;
}
tap_fd = RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0));
if (tap_fd < 0) {
- error_setg(errp, "Can't open /dev/tap");
+ error_setg_file_open(errp, errno, "/dev/tap");
return -1;
}
@@ -107,7 +107,7 @@ static int tap_alloc(char *dev, size_t dev_size, Error **errp)
if_fd = RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0));
if (if_fd < 0) {
- error_setg(errp, "Can't open /dev/tap (2)");
+ error_setg_file_open(errp, errno, "/dev/tap");
return -1;
}
if(ioctl(if_fd, I_PUSH, "ip") < 0){
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 09/17] qga: Use error_setg_file_open() for better error messages
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (7 preceding siblings ...)
2026-01-07 12:43 ` [PULL 08/17] tap-solaris: Use error_setg_file_open() for better error messages Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 10/17] net/tap: Use error_setg_file_open() for a better error message Markus Armbruster
` (7 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Dr. David Alan Gilbert, Kostiantyn Kostiuk
Error messages change from
open("FNAME"): REASON
to
Could not open 'FNAME': REASON
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Message-ID: <20251121121438.1249498-6-armbru@redhat.com>
---
qga/commands-linux.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index c639a60a94..ae2c4d442a 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -1503,14 +1503,15 @@ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
if (dirfd == -1) {
- error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
+ error_setg_file_open(errp, errno, dirpath);
return;
}
fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR);
if (fd == -1) {
if (errno != ENOENT) {
- error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn);
+ error_setg_errno(errp, errno, "could not open %s/%s",
+ dirpath, fn);
} else if (sys2vcpu) {
vcpu->online = true;
vcpu->can_offline = false;
@@ -1712,7 +1713,7 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
dirfd = open(dirpath, O_RDONLY | O_DIRECTORY);
if (dirfd == -1) {
if (sys2memblk) {
- error_setg_errno(errp, errno, "open(\"%s\")", dirpath);
+ error_setg_file_open(errp, errno, dirpath);
} else {
if (errno == ENOENT) {
result->response = GUEST_MEMORY_BLOCK_RESPONSE_TYPE_NOT_FOUND;
@@ -1937,7 +1938,7 @@ static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp)
fp = fopen(diskstats, "r");
if (fp == NULL) {
- error_setg_errno(errp, errno, "open(\"%s\")", diskstats);
+ error_setg_file_open(errp, errno, diskstats);
return NULL;
}
@@ -2048,7 +2049,7 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
fp = fopen(cpustats, "r");
if (fp == NULL) {
- error_setg_errno(errp, errno, "open(\"%s\")", cpustats);
+ error_setg_file_open(errp, errno, cpustats);
return NULL;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 10/17] net/tap: Use error_setg_file_open() for a better error message
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (8 preceding siblings ...)
2026-01-07 12:43 ` [PULL 09/17] qga: " Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 11/17] blkdebug: " Markus Armbruster
` (6 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Philippe Mathieu-Daudé
The error message changes from
tap: open vhost char device failed
to
Could not open '/dev/vhost-net': REASON
I think the exact file name is more useful to know than the file's
purpose.
We could put back the "tap: " prefix with error_prepend(). Not
worth the bother.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-9-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
net/tap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index abe3b2d036..bfba3fd7a7 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -747,8 +747,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
} else {
vhostfd = open("/dev/vhost-net", O_RDWR);
if (vhostfd < 0) {
- error_setg_errno(errp, errno,
- "tap: open vhost char device failed");
+ error_setg_file_open(errp, errno, "/dev/vhost-net");
goto failed;
}
if (!qemu_set_blocking(vhostfd, false, errp)) {
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 11/17] blkdebug: Use error_setg_file_open() for a better error message
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (9 preceding siblings ...)
2026-01-07 12:43 ` [PULL 10/17] net/tap: Use error_setg_file_open() for a better error message Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 12/17] error: Use error_setg_file_open() for simplicity and consistency Markus Armbruster
` (5 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson
The error message changes from
Could not read blkdebug config file: REASON
to
Could not open 'FNAME': REASON
I think the exact file name is more useful to know than the file's
purpose.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-10-armbru@redhat.com>
---
block/blkdebug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index c54aee0c84..8a4a8cb85e 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -288,7 +288,7 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,
if (filename) {
f = fopen(filename, "r");
if (f == NULL) {
- error_setg_errno(errp, errno, "Could not read blkdebug config file");
+ error_setg_file_open(errp, errno, filename);
return -errno;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 12/17] error: Use error_setg_file_open() for simplicity and consistency
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (10 preceding siblings ...)
2026-01-07 12:43 ` [PULL 11/17] blkdebug: " Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 13/17] net/slirp: Improve file open error message Markus Armbruster
` (4 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Dr. David Alan Gilbert
Replace
error_setg_errno(errp, errno, MSG, FNAME);
by
error_setg_file_open(errp, errno, FNAME);
where MSG is "Could not open '%s'" or similar.
Also replace equivalent uses of error_setg().
A few messages lose prefixes ("net dump: ", "SEV: ", __func__ ": ").
We could put them back with error_prepend(). Not worth the bother.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Message-ID: <20251121121438.1249498-11-armbru@redhat.com>
[Conflict with commit 26b4a6ffe7f (monitor/hmp: Merge
hmp-cmds-target.c within hmp-cmds.c) resolved]
---
hw/9pfs/9p-local.c | 2 +-
hw/acpi/core.c | 2 +-
hw/core/loader.c | 2 +-
hw/pci-host/xen_igd_pt.c | 2 +-
monitor/hmp-cmds.c | 2 +-
net/dump.c | 2 +-
net/tap-bsd.c | 6 +++---
net/tap-linux.c | 2 +-
target/i386/sev.c | 6 ++----
util/vfio-helpers.c | 5 ++---
10 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 31e216227c..376b377698 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1456,7 +1456,7 @@ static int local_init(FsContext *ctx, Error **errp)
data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
if (data->mountfd == -1) {
- error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root);
+ error_setg_file_open(errp, errno, ctx->fs_root);
goto err;
}
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 2b74bed882..4e030d8e3b 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -277,7 +277,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
int fd = open(*cur, O_RDONLY | O_BINARY);
if (fd < 0) {
- error_setg(errp, "can't open file %s: %s", *cur, strerror(errno));
+ error_setg_file_open(errp, errno, *cur);
goto out;
}
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 89d67d2760..16c11a4643 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -380,7 +380,7 @@ bool load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp)
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
- error_setg_errno(errp, errno, "Failed to open file: %s", filename);
+ error_setg_file_open(errp, errno, filename);
return false;
}
if (read(fd, hdr, EI_NIDENT) != EI_NIDENT) {
diff --git a/hw/pci-host/xen_igd_pt.c b/hw/pci-host/xen_igd_pt.c
index 5dd17ef236..f6016f2cd5 100644
--- a/hw/pci-host/xen_igd_pt.c
+++ b/hw/pci-host/xen_igd_pt.c
@@ -55,7 +55,7 @@ static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp)
config_fd = open(path, O_RDWR);
if (config_fd < 0) {
- error_setg_errno(errp, errno, "Failed to open: %s", path);
+ error_setg_file_open(errp, errno, path);
goto out;
}
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index f7ff6ec90e..5a673cddb2 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -740,7 +740,7 @@ static uint64_t vtop(void *ptr, Error **errp)
fd = open("/proc/self/pagemap", O_RDONLY);
if (fd == -1) {
- error_setg_errno(errp, errno, "Cannot open /proc/self/pagemap");
+ error_setg_file_open(errp, errno, "/proc/self/pagemap");
return -1;
}
diff --git a/net/dump.c b/net/dump.c
index 581234b775..0c39f09892 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -111,7 +111,7 @@ static int net_dump_state_init(DumpState *s, const char *filename,
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644);
if (fd < 0) {
- error_setg_errno(errp, errno, "net dump: can't open %s", filename);
+ error_setg_file_open(errp, errno, filename);
return -1;
}
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index bbf84d1828..3fd300d46f 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -68,7 +68,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
}
}
if (fd < 0) {
- error_setg_errno(errp, errno, "could not open %s", dname);
+ error_setg_file_open(errp, errno, dname);
return -1;
}
@@ -118,7 +118,7 @@ static int tap_open_clone(char *ifname, int ifname_size, Error **errp)
fd = RETRY_ON_EINTR(open(PATH_NET_TAP, O_RDWR));
if (fd < 0) {
- error_setg_errno(errp, errno, "could not open %s", PATH_NET_TAP);
+ error_setg_file_open(errp, errno, PATH_NET_TAP);
return -1;
}
@@ -166,7 +166,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
snprintf(dname, sizeof dname, "/dev/%s", ifname);
fd = RETRY_ON_EINTR(open(dname, O_RDWR));
if (fd < 0 && errno != ENOENT) {
- error_setg_errno(errp, errno, "could not open %s", dname);
+ error_setg_file_open(errp, errno, dname);
return -1;
}
}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 2a90b58467..909c4f1fcf 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -57,7 +57,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
if (fd < 0) {
fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
if (fd < 0) {
- error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
+ error_setg_file_open(errp, errno, PATH_NET_TUN);
return -1;
}
}
diff --git a/target/i386/sev.c b/target/i386/sev.c
index fb5a3b5d77..1d70f96ec1 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -892,8 +892,7 @@ static SevCapability *sev_get_capabilities(Error **errp)
fd = open(sev_device, O_RDWR);
if (fd < 0) {
- error_setg_errno(errp, errno, "SEV: Failed to open %s",
- sev_device);
+ error_setg_file_open(errp, errno, sev_device);
g_free(sev_device);
return NULL;
}
@@ -1820,8 +1819,7 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
devname = object_property_get_str(OBJECT(sev_common), "sev-device", NULL);
sev_common->sev_fd = open(devname, O_RDWR);
if (sev_common->sev_fd < 0) {
- error_setg(errp, "%s: Failed to open %s '%s'", __func__,
- devname, strerror(errno));
+ error_setg_file_open(errp, errno, devname);
g_free(devname);
return -1;
}
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 44b457c442..c619516163 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -309,7 +309,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
s->container = open("/dev/vfio/vfio", O_RDWR);
if (s->container == -1) {
- error_setg_errno(errp, errno, "Failed to open /dev/vfio/vfio");
+ error_setg_file_open(errp, errno, "/dev/vfio/vfio");
return -errno;
}
if (ioctl(s->container, VFIO_GET_API_VERSION) != VFIO_API_VERSION) {
@@ -333,8 +333,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,
s->group = open(group_file, O_RDWR);
if (s->group == -1) {
- error_setg_errno(errp, errno, "Failed to open VFIO group file: %s",
- group_file);
+ error_setg_file_open(errp, errno, group_file);
g_free(group_file);
ret = -errno;
goto fail_container;
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 13/17] net/slirp: Improve file open error message
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (11 preceding siblings ...)
2026-01-07 12:43 ` [PULL 12/17] error: Use error_setg_file_open() for simplicity and consistency Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 14/17] error: Use error_setg_errno() to improve error messages Markus Armbruster
` (3 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Philippe Mathieu-Daudé
This error reports failure to create a temporary file, and
error_setg_file_open() would probably be too terse, so merely switch
to error_setg_errno() to add errno information.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-12-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
net/slirp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/slirp.c b/net/slirp.c
index 120eef6122..5996fec512 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -1034,8 +1034,10 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
f = fopen(smb_conf, "w");
if (!f) {
+ int eno = errno;
+
slirp_smb_cleanup(s);
- error_setg(errp,
+ error_setg_errno(errp, eno,
"Could not create samba server configuration file '%s'",
smb_conf);
g_free(smb_conf);
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 14/17] error: Use error_setg_errno() to improve error messages
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (12 preceding siblings ...)
2026-01-07 12:43 ` [PULL 13/17] net/slirp: Improve file open error message Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-08 4:15 ` Richard Henderson
2026-01-07 12:43 ` [PULL 15/17] error: Use error_setg_errno() for simplicity and consistency Markus Armbruster
` (2 subsequent siblings)
16 siblings, 1 reply; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Philippe Mathieu-Daudé
A few error messages show numeric errno codes. Use error_setg_errno()
to show human-readable text instead.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-13-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
backends/cryptodev-lkcf.c | 2 +-
hw/ppc/spapr.c | 6 +++---
hw/vfio/migration-multifd.c | 5 +++--
migration/rdma.c | 3 +--
net/l2tpv3.c | 6 ++----
target/riscv/kvm/kvm-cpu.c | 11 ++++++-----
6 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c
index 97a8a8812c..40c7bd3c5a 100644
--- a/backends/cryptodev-lkcf.c
+++ b/backends/cryptodev-lkcf.c
@@ -218,7 +218,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp)
}
lkcf->eventfd = eventfd(0, 0);
if (lkcf->eventfd < 0) {
- error_setg(errp, "Failed to create eventfd: %d", errno);
+ error_setg_errno(errp, errno, "Failed to create eventfd");
return;
}
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index b3c5097bf8..f129e4ec39 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2700,9 +2700,9 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
ret = kvmppc_set_smt_threads(spapr->vsmt);
if (ret) {
/* Looks like KVM isn't able to change VSMT mode */
- error_setg(&local_err,
- "Failed to set KVM's VSMT mode to %d (errno %d)",
- spapr->vsmt, ret);
+ error_setg_errno(&local_err, -ret,
+ "Failed to set KVM's VSMT mode to %d",
+ spapr->vsmt);
/* We can live with that if the default one is big enough
* for the number of threads, and a submultiple of the one
* we want. In this case we'll waste some vcpu ids, but
diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index e4785031a7..4a855f4e12 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -725,8 +725,9 @@ vfio_multifd_save_complete_precopy_thread(SaveCompletePrecopyThreadData *d,
data_size = read(migration->data_fd, &packet->data,
migration->data_buffer_size);
if (data_size < 0) {
- error_setg(errp, "%s: reading state buffer %" PRIu32 " failed: %d",
- vbasedev->name, idx, errno);
+ error_setg_errno(errp, errno,
+ "%s: reading state buffer %" PRIu32 " failed",
+ vbasedev->name, idx);
goto thread_exit;
} else if (data_size == 0) {
break;
diff --git a/migration/rdma.c b/migration/rdma.c
index 337b415889..9e301cf917 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -2349,8 +2349,7 @@ static int qemu_get_cm_event_timeout(RDMAContext *rdma,
error_setg(errp, "RDMA ERROR: poll cm event timeout");
return -1;
} else if (ret < 0) {
- error_setg(errp, "RDMA ERROR: failed to poll cm event, errno=%i",
- errno);
+ error_setg_errno(errp, errno, "RDMA ERROR: failed to poll cm event");
return -1;
} else if (poll_fd.revents & POLLIN) {
if (rdma_get_cm_event(rdma->channel, cm_event) < 0) {
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index cdfc641aa6..3044fa4608 100644
--- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -639,13 +639,11 @@ int net_init_l2tpv3(const Netdev *netdev,
}
fd = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (fd == -1) {
- fd = -errno;
- error_setg(errp, "socket creation failed, errno = %d",
- -fd);
+ error_setg_errno(errp, errno, "socket creation failed");
goto outerr;
}
if (bind(fd, (struct sockaddr *) result->ai_addr, result->ai_addrlen)) {
- error_setg(errp, "could not bind socket err=%i", errno);
+ error_setg_errno(errp, errno, "could not bind socket");
goto outerr;
}
if (!qemu_set_blocking(fd, false, errp)) {
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 5d792563b9..99284abbc6 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1996,8 +1996,8 @@ static bool kvm_cpu_realize(CPUState *cs, Error **errp)
if (riscv_has_ext(&cpu->env, RVV)) {
ret = prctl(PR_RISCV_V_SET_CONTROL, PR_RISCV_V_VSTATE_CTRL_ON);
if (ret) {
- error_setg(errp, "Error in prctl PR_RISCV_V_SET_CONTROL, code: %s",
- strerrorname_np(errno));
+ error_setg_errno(errp, errno,
+ "Error in prctl PR_RISCV_V_SET_CONTROL");
return false;
}
}
@@ -2032,7 +2032,8 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
reg.addr = (uint64_t)&val;
ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
if (ret != 0) {
- error_setg(errp, "Unable to read cbom_blocksize, error %d", errno);
+ error_setg(errp, errno,
+ "Unable to read cbom_blocksize");
return;
}
@@ -2051,7 +2052,7 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
reg.addr = (uint64_t)&val;
ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
if (ret != 0) {
- error_setg(errp, "Unable to read cboz_blocksize, error %d", errno);
+ error_setg_errno(errp, errno, "Unable to read cboz_blocksize");
return;
}
@@ -2073,7 +2074,7 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
reg.addr = (uint64_t)&val;
ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
if (ret != 0) {
- error_setg(errp, "Unable to read vlenb register, error %d", errno);
+ error_setg_errno(errp, errno, "Unable to read vlenb register");
return;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PULL 14/17] error: Use error_setg_errno() to improve error messages
2026-01-07 12:43 ` [PULL 14/17] error: Use error_setg_errno() to improve error messages Markus Armbruster
@ 2026-01-08 4:15 ` Richard Henderson
2026-01-08 6:55 ` Markus Armbruster
0 siblings, 1 reply; 20+ messages in thread
From: Richard Henderson @ 2026-01-08 4:15 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: Philippe Mathieu-Daudé
On 1/7/26 23:43, Markus Armbruster wrote:
> @@ -2032,7 +2032,8 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> reg.addr = (uint64_t)&val;
> ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
> if (ret != 0) {
> - error_setg(errp, "Unable to read cbom_blocksize, error %d", errno);
> + error_setg(errp, errno,
> + "Unable to read cbom_blocksize");
> return;
> }
>
Missed changing the function.
../target/riscv/kvm/kvm-cpu.c:2035:13: error: passing argument 5 of ‘error_setg_internal’
makes pointer from integer without a cast [-Wint-conversion]
2035 | error_setg(errp, errno,
| ^~~~~~~~~~
| |
| int
In file included from ../target/riscv/kvm/kvm-cpu.c:26:
../include/qapi/error.h:322:38: note: expected ‘const char *’ but argument is of type ‘int’
322 | const char *fmt, ...)
| ~~~~~~~~~~~~^~~
https://gitlab.com/qemu-project/qemu/-/jobs/12639739827
r~
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PULL 14/17] error: Use error_setg_errno() to improve error messages
2026-01-08 4:15 ` Richard Henderson
@ 2026-01-08 6:55 ` Markus Armbruster
0 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-08 6:55 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel, Philippe Mathieu-Daudé
Richard Henderson <richard.henderson@linaro.org> writes:
> On 1/7/26 23:43, Markus Armbruster wrote:
>> @@ -2032,7 +2032,8 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
>> reg.addr = (uint64_t)&val;
>> ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
>> if (ret != 0) {
>> - error_setg(errp, "Unable to read cbom_blocksize, error %d", errno);
>> + error_setg(errp, errno,
>> + "Unable to read cbom_blocksize");
>> return;
>> }
>>
>
> Missed changing the function.
[...]
Sorry about that. v2 coming.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PULL 15/17] error: Use error_setg_errno() for simplicity and consistency
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (13 preceding siblings ...)
2026-01-07 12:43 ` [PULL 14/17] error: Use error_setg_errno() to improve error messages Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 16/17] qga/commands-win32: Use error_setg_win32() for better error messages Markus Armbruster
2026-01-07 12:43 ` [PULL 17/17] block/file-win32: Improve an error message Markus Armbruster
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Jagannathan Raman, Philippe Mathieu-Daudé
Use error_setg_errno() instead of passing the value of strerror() or
g_strerror() to error_setg().
The separator between the error message proper and the value of
strerror() changes from " : ", "", " - ", "- " to ": " in places.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-14-armbru@redhat.com>
Acked-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
backends/spdm-socket.c | 4 ++--
backends/tpm/tpm_emulator.c | 13 +++++--------
hw/9pfs/9p.c | 3 +--
hw/acpi/core.c | 3 +--
hw/intc/openpic_kvm.c | 3 +--
hw/intc/xics_kvm.c | 5 +++--
hw/remote/vfio-user-obj.c | 18 +++++++++---------
hw/sensor/emc141x.c | 4 ++--
hw/sensor/tmp421.c | 4 ++--
hw/smbios/smbios.c | 4 ++--
hw/virtio/vdpa-dev.c | 4 ++--
migration/postcopy-ram.c | 10 +++++-----
net/slirp.c | 5 +++--
qga/commands-posix-ssh.c | 23 +++++++++++++----------
system/vl.c | 2 +-
target/ppc/kvm.c | 5 ++---
16 files changed, 54 insertions(+), 56 deletions(-)
diff --git a/backends/spdm-socket.c b/backends/spdm-socket.c
index bc5c7afb3c..b625a65d28 100644
--- a/backends/spdm-socket.c
+++ b/backends/spdm-socket.c
@@ -167,7 +167,7 @@ int spdm_socket_connect(uint16_t port, Error **errp)
client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (client_socket < 0) {
- error_setg(errp, "cannot create socket: %s", strerror(errno));
+ error_setg_errno(errp, errno, "cannot create socket");
return -1;
}
@@ -179,7 +179,7 @@ int spdm_socket_connect(uint16_t port, Error **errp)
if (connect(client_socket, (struct sockaddr *)&server_addr,
sizeof(server_addr)) < 0) {
- error_setg(errp, "cannot connect: %s", strerror(errno));
+ error_setg_errno(errp, errno, "cannot connect");
close(client_socket);
return -1;
}
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index f10b9074fb..f52cb4d435 100644
--- a/backends/tpm/tpm_emulator.c
+++ b/backends/tpm/tpm_emulator.c
@@ -225,8 +225,7 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number,
if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_LOCALITY, &loc,
sizeof(loc), sizeof(loc.u.resp.tpm_result),
sizeof(loc)) < 0) {
- error_setg(errp, "tpm-emulator: could not set locality : %s",
- strerror(errno));
+ error_setg_errno(errp, errno, "tpm-emulator: could not set locality");
return -1;
}
@@ -315,8 +314,7 @@ static int tpm_emulator_stop_tpm(TPMBackend *tb, Error **errp)
if (tpm_emulator_ctrlcmd(tpm_emu, CMD_STOP, &res, 0,
sizeof(ptm_res), sizeof(res)) < 0) {
- error_setg(errp, "tpm-emulator: Could not stop TPM: %s",
- strerror(errno));
+ error_setg_errno(errp, errno, "tpm-emulator: Could not stop TPM");
return -1;
}
@@ -377,8 +375,8 @@ static int tpm_emulator_set_buffer_size(TPMBackend *tb,
if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_BUFFERSIZE, &psbs,
sizeof(psbs.u.req), sizeof(psbs.u.resp.tpm_result),
sizeof(psbs.u.resp)) < 0) {
- error_setg(errp, "tpm-emulator: Could not set buffer size: %s",
- strerror(errno));
+ error_setg_errno(errp, errno,
+ "tpm-emulator: Could not set buffer size");
return -1;
}
@@ -426,8 +424,7 @@ static int tpm_emulator_startup_tpm_resume(TPMBackend *tb, size_t buffersize,
if (tpm_emulator_ctrlcmd(tpm_emu, CMD_INIT, &init, sizeof(init),
sizeof(init.u.resp.tpm_result),
sizeof(init)) < 0) {
- error_setg(errp, "tpm-emulator: could not send INIT: %s",
- strerror(errno));
+ error_setg_errno(errp, errno, "tpm-emulator: could not send INIT");
goto err_exit;
}
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index bc4a016ee3..6fbe604ce8 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -4345,8 +4345,7 @@ int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
* use co-routines here.
*/
if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
- error_setg(errp,
- "error in converting name to path %s", strerror(errno));
+ error_setg_errno(errp, errno, "error in converting name to path");
goto out;
}
if (s->ops->lstat(&s->ctx, &path, &stat)) {
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 4e030d8e3b..d9979b0da9 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -293,8 +293,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
memcpy(blob + bloblen, data, r);
bloblen += r;
} else if (errno != EINTR) {
- error_setg(errp, "can't read file %s: %s", *cur,
- strerror(errno));
+ error_setg_errno(errp, errno, "can't read file %s", *cur);
close(fd);
goto out;
}
diff --git a/hw/intc/openpic_kvm.c b/hw/intc/openpic_kvm.c
index 9aafef5d9e..fbf0bdbe07 100644
--- a/hw/intc/openpic_kvm.c
+++ b/hw/intc/openpic_kvm.c
@@ -223,8 +223,7 @@ static void kvm_openpic_realize(DeviceState *dev, Error **errp)
cd.type = kvm_openpic_model;
ret = kvm_vm_ioctl(s, KVM_CREATE_DEVICE, &cd);
if (ret < 0) {
- error_setg(errp, "Can't create device %d: %s",
- cd.type, strerror(errno));
+ error_setg_errno(errp, errno, "Can't create device %d", cd.type);
return;
}
opp->fd = cd.fd;
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index ee72969f5f..61f66d1019 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -165,8 +165,9 @@ void icp_kvm_realize(DeviceState *dev, Error **errp)
if (ret < 0) {
Error *local_err = NULL;
- error_setg(&local_err, "Unable to connect CPU%ld to kernel XICS: %s",
- vcpu_id, strerror(errno));
+ error_setg_errno(&local_err, errno,
+ "Unable to connect CPU%ld to kernel XICS",
+ vcpu_id);
if (errno == ENOSPC) {
error_append_hint(&local_err, "Try -smp maxcpus=N with N < %u\n",
MACHINE(qdev_get_machine())->smp.max_cpus);
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 4eb036a546..12ecdab6de 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -751,7 +751,7 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
LIBVFIO_USER_FLAG_ATTACH_NB,
o, VFU_DEV_TYPE_PCI);
if (o->vfu_ctx == NULL) {
- error_setg(errp, "vfu: Failed to create context - %s", strerror(errno));
+ error_setg_errno(errp, errno, "vfu: Failed to create context");
return;
}
@@ -776,9 +776,9 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0);
if (ret < 0) {
- error_setg(errp,
- "vfu: Failed to attach PCI device %s to context - %s",
- o->device, strerror(errno));
+ error_setg_errno(errp, errno,
+ "vfu: Failed to attach PCI device %s to context",
+ o->device);
goto fail;
}
@@ -792,9 +792,9 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB,
NULL, 0, -1, 0);
if (ret < 0) {
- error_setg(errp,
- "vfu: Failed to setup config space handlers for %s- %s",
- o->device, strerror(errno));
+ error_setg_errno(errp, errno,
+ "vfu: Failed to setup config space handlers for %s",
+ o->device);
goto fail;
}
@@ -822,8 +822,8 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
ret = vfu_realize_ctx(o->vfu_ctx);
if (ret < 0) {
- error_setg(errp, "vfu: Failed to realize device %s- %s",
- o->device, strerror(errno));
+ error_setg_errno(errp, errno, "vfu: Failed to realize device %s",
+ o->device);
goto fail;
}
diff --git a/hw/sensor/emc141x.c b/hw/sensor/emc141x.c
index 7b2ce383a1..a51fc44395 100644
--- a/hw/sensor/emc141x.c
+++ b/hw/sensor/emc141x.c
@@ -59,7 +59,7 @@ static void emc141x_get_temperature(Object *obj, Visitor *v, const char *name,
unsigned tempid;
if (sscanf(name, "temperature%u", &tempid) != 1) {
- error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
+ error_setg_errno(errp, errno, "error reading %s", name);
return;
}
@@ -86,7 +86,7 @@ static void emc141x_set_temperature(Object *obj, Visitor *v, const char *name,
}
if (sscanf(name, "temperature%u", &tempid) != 1) {
- error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
+ error_setg_errno(errp, errno, "error reading %s", name);
return;
}
diff --git a/hw/sensor/tmp421.c b/hw/sensor/tmp421.c
index 3421c44086..127edd0ba5 100644
--- a/hw/sensor/tmp421.c
+++ b/hw/sensor/tmp421.c
@@ -117,7 +117,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
int tempid;
if (sscanf(name, "temperature%d", &tempid) != 1) {
- error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
+ error_setg_errno(errp, errno, "error reading %s", name);
return;
}
@@ -154,7 +154,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
}
if (sscanf(name, "temperature%d", &tempid) != 1) {
- error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
+ error_setg_errno(errp, errno, "error reading %s", name);
return;
}
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index be97a5effc..7d7141851b 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -1281,8 +1281,8 @@ static int save_opt_one(void *opaque,
break;
}
if (ret < 0) {
- error_setg(errp, "Unable to read from %s: %s",
- value, strerror(errno));
+ error_setg_errno(errp, errno, "Unable to read from %s",
+ value);
qemu_close(fd);
return -1;
}
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
index f2377d2d50..4532d63653 100644
--- a/hw/virtio/vdpa-dev.c
+++ b/hw/virtio/vdpa-dev.c
@@ -41,8 +41,8 @@ vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp)
uint32_t val = (uint32_t)-1;
if (ioctl(fd, cmd, &val) < 0) {
- error_setg(errp, "vhost-vdpa-device: cmd 0x%lx failed: %s",
- cmd, strerror(errno));
+ error_setg_errno(errp, errno, "vhost-vdpa-device: cmd 0x%lx failed",
+ cmd);
}
return val;
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 98a98138be..ac410676ef 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -582,7 +582,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)
ufd = uffd_open(O_CLOEXEC);
if (ufd == -1) {
- error_setg(errp, "Userfaultfd not available: %s", strerror(errno));
+ error_setg_errno(errp, errno, "Userfaultfd not available");
goto out;
}
@@ -620,7 +620,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)
* it was enabled.
*/
if (munlockall()) {
- error_setg(errp, "munlockall() failed: %s", strerror(errno));
+ error_setg_errno(errp, errno, "munlockall() failed");
goto out;
}
@@ -632,7 +632,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)
testarea = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
if (testarea == MAP_FAILED) {
- error_setg(errp, "Failed to map test area: %s", strerror(errno));
+ error_setg_errno(errp, errno, "Failed to map test area");
goto out;
}
g_assert(QEMU_PTR_IS_ALIGNED(testarea, pagesize));
@@ -642,14 +642,14 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)
reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
if (ioctl(ufd, UFFDIO_REGISTER, ®_struct)) {
- error_setg(errp, "UFFDIO_REGISTER failed: %s", strerror(errno));
+ error_setg_errno(errp, errno, "UFFDIO_REGISTER failed");
goto out;
}
range_struct.start = (uintptr_t)testarea;
range_struct.len = pagesize;
if (ioctl(ufd, UFFDIO_UNREGISTER, &range_struct)) {
- error_setg(errp, "UFFDIO_UNREGISTER failed: %s", strerror(errno));
+ error_setg_errno(errp, errno, "UFFDIO_UNREGISTER failed");
goto out;
}
diff --git a/net/slirp.c b/net/slirp.c
index 5996fec512..04925f3318 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -1020,8 +1020,9 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
}
if (access(exported_dir, R_OK | X_OK)) {
- error_setg(errp, "Error accessing shared directory '%s': %s",
- exported_dir, strerror(errno));
+ error_setg_errno(errp, errno,
+ "Error accessing shared directory '%s'",
+ exported_dir);
return -1;
}
diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
index 246171d323..661972e34e 100644
--- a/qga/commands-posix-ssh.c
+++ b/qga/commands-posix-ssh.c
@@ -61,20 +61,22 @@ mkdir_for_user(const char *path, const struct passwd *p,
mode_t mode, Error **errp)
{
if (g_mkdir(path, mode) == -1) {
- error_setg(errp, "failed to create directory '%s': %s",
- path, g_strerror(errno));
+ error_setg_errno(errp, errno, "failed to create directory '%s'",
+ path);
return false;
}
if (chown(path, p->pw_uid, p->pw_gid) == -1) {
- error_setg(errp, "failed to set ownership of directory '%s': %s",
- path, g_strerror(errno));
+ error_setg_errno(errp, errno,
+ "failed to set ownership of directory '%s'",
+ path);
return false;
}
if (chmod(path, mode) == -1) {
- error_setg(errp, "failed to set permissions of directory '%s': %s",
- path, g_strerror(errno));
+ error_setg_errno(errp, errno,
+ "failed to set permissions of directory '%s'",
+ path);
return false;
}
@@ -95,14 +97,15 @@ write_authkeys(const char *path, const GStrv keys,
}
if (chown(path, p->pw_uid, p->pw_gid) == -1) {
- error_setg(errp, "failed to set ownership of directory '%s': %s",
- path, g_strerror(errno));
+ error_setg_errno(errp, errno,
+ "failed to set ownership of directory '%s'",
+ path);
return false;
}
if (chmod(path, 0600) == -1) {
- error_setg(errp, "failed to set permissions of '%s': %s",
- path, g_strerror(errno));
+ error_setg_errno(errp, errno, "failed to set permissions of '%s'",
+ path);
return false;
}
diff --git a/system/vl.c b/system/vl.c
index b60b883050..aa9a155041 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -618,7 +618,7 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
}
#endif
if (dupfd == -1) {
- error_setg(errp, "error duplicating fd: %s", strerror(errno));
+ error_setg_errno(errp, errno, "error duplicating fd");
return -1;
}
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 3b2f1077da..1521787b3f 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2699,9 +2699,8 @@ int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp)
ret = kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &s);
if (ret < 0) {
- error_setg(errp, "Unable to open fd for %s HPT %s KVM: %s",
- write ? "writing" : "reading", write ? "to" : "from",
- strerror(errno));
+ error_setg_errno(errp, errno, "Unable to open fd for %s HPT %s KVM",
+ write ? "writing" : "reading", write ? "to" : "from");
return -errno;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 16/17] qga/commands-win32: Use error_setg_win32() for better error messages
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (14 preceding siblings ...)
2026-01-07 12:43 ` [PULL 15/17] error: Use error_setg_errno() for simplicity and consistency Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
2026-01-07 12:43 ` [PULL 17/17] block/file-win32: Improve an error message Markus Armbruster
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel
Cc: richard.henderson, Kostiantyn Kostiuk,
Philippe Mathieu-Daudé
We include numeric GetLastError() codes in error messages in a few
places, like this:
error_setg(errp, "GRIPE: %d", (int)GetLastError());
Show text instead, like this:
error_setg_win32(errp, GetLastError(), "GRIPE");
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-15-armbru@redhat.com>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
qga/commands-win32.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index acc2c11589..0fd0c966e4 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1798,8 +1798,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
tf.dwHighDateTime = (DWORD) (time >> 32);
if (!FileTimeToSystemTime(&tf, &ts)) {
- error_setg(errp, "Failed to convert system time %d",
- (int)GetLastError());
+ error_setg_win32(errp, GetLastError(),
+ "Failed to convert system time");
return;
}
@@ -1810,7 +1810,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
}
if (!SetSystemTime(&ts)) {
- error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError());
+ error_setg_win32(errp, GetLastError(),
+ "Failed to set time to guest");
return;
}
}
@@ -1834,13 +1835,12 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
(length > sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION))) {
ptr = pslpi = g_malloc0(length);
if (GetLogicalProcessorInformation(pslpi, &length) == FALSE) {
- error_setg(&local_err, "Failed to get processor information: %d",
- (int)GetLastError());
+ error_setg_win32(&local_err, GetLastError(),
+ "Failed to get processor information");
}
} else {
- error_setg(&local_err,
- "Failed to get processor information buffer length: %d",
- (int)GetLastError());
+ error_setg_win32(&local_err, GetLastError(),
+ "Failed to get processor information buffer length");
}
while ((local_err == NULL) && (length > 0)) {
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PULL 17/17] block/file-win32: Improve an error message
2026-01-07 12:43 [PULL 00/17] Error reporting patches for 2026-01-07 Markus Armbruster
` (15 preceding siblings ...)
2026-01-07 12:43 ` [PULL 16/17] qga/commands-win32: Use error_setg_win32() for better error messages Markus Armbruster
@ 2026-01-07 12:43 ` Markus Armbruster
16 siblings, 0 replies; 20+ messages in thread
From: Markus Armbruster @ 2026-01-07 12:43 UTC (permalink / raw)
To: qemu-devel; +Cc: richard.henderson, Philippe Mathieu-Daudé
Two out of three calls of CreateFile() use error_setg_win32() to
report errors. The third uses error_setg_errno(), mapping
ERROR_ACCESS_DENIED to EACCES, and everything else to EINVAL, throwing
away detail. Switch it to error_setg_win32().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20251121121438.1249498-16-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
block/file-win32.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/file-win32.c b/block/file-win32.c
index b00039bf94..b63ce1c189 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -872,7 +872,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
} else {
ret = -EINVAL;
}
- error_setg_errno(errp, -ret, "Could not open device");
+ error_setg_win32(errp, err, "Could not open device");
goto done;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 20+ messages in thread