Error reporting patches for 2026-01-07
Subsystems (3)
The following changes since commit 0fc482b73d8e085d1375b4e17b0647fd2e6fe8f0:
Merge tag 'pull-aspeed-20260105' of https://github.com/legoater/qemu into staging (2026-01-06 06:52:47 +1100)
are available in the Git repository at:
https://repo.or.cz/qemu/armbru.git tags/pull-error-2026-01-07
for you to fetch changes up to fefb4605b37fd59b53ae9cf89d6beedaab72f640:
block/file-win32: Improve an error message (2026-01-07 13:25:01 +0100)
----------------------------------------------------------------
Error reporting patches for 2026-01-07
----------------------------------------------------------------
Markus Armbruster (17):
hw/core/loader: Make load_elf_hdr() return bool, simplify caller hw/nvram/xlnx-bbram: More idiomatic and simpler error reporting nbd/client-connection: Replace error_propagate() by assignment
error: error_free(NULL) is safe, drop unnecessary conditionals
error: Consistently name Error * objects err, and not errp
error: Strip trailing '\n' from error string arguments (again)
ui: Convert to qemu_create() for simplicity and consistency
tap-solaris: Use error_setg_file_open() for better error messages
qga: Use error_setg_file_open() for better error messages net/tap: Use error_setg_file_open() for a better error message
blkdebug: Use error_setg_file_open() for a better error message
error: Use error_setg_file_open() for simplicity and consistency net/slirp: Improve file open error message
error: Use error_setg_errno() to improve error messages
error: Use error_setg_errno() for simplicity and consistency qga/commands-win32: Use error_setg_win32() for better error messages block/file-win32: Improve an error message
include/hw/core/loader.h | 4 +++- backends/cryptodev-lkcf.c | 2 +- backends/spdm-socket.c | 4 ++-- backends/tpm/tpm_emulator.c | 13 +++++-------- block/blkdebug.c | 2 +- block/crypto.c | 8 ++++---- block/file-win32.c | 2 +- hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p.c | 3 +-- hw/acpi/core.c | 5 ++--- hw/acpi/ghes.c | 8 ++++---- hw/acpi/pcihp.c | 4 +--- hw/arm/boot.c | 6 +----- hw/audio/es1370.c | 2 +- hw/core/loader.c | 10 +++++++--- hw/intc/openpic_kvm.c | 3 +-- hw/intc/xics_kvm.c | 5 +++-- hw/nvram/xlnx-bbram.c | 18 ++++-------------- hw/pci-host/xen_igd_pt.c | 2 +- hw/ppc/spapr.c | 22 +++++++++++----------- hw/remote/vfio-user-obj.c | 18 +++++++++--------- hw/riscv/spike.c | 10 +--------- hw/sensor/emc141x.c | 4 ++-- hw/sensor/tmp421.c | 4 ++-- hw/smbios/smbios.c | 4 ++-- hw/vfio/migration-multifd.c | 5 +++-- hw/virtio/vdpa-dev.c | 4 ++-- hw/xen/xen-pvh-common.c | 13 ++++++++++--- io/channel-websock.c | 4 +--- io/task.c | 4 +--- migration/migration.c | 6 ++---- migration/postcopy-ram.c | 10 +++++----- migration/rdma.c | 3 +-- monitor/hmp-cmds.c | 2 +- nbd/client-connection.c | 3 +-- nbd/common.c | 6 +++--- net/dump.c | 2 +- net/l2tpv3.c | 6 ++---- net/slirp.c | 9 ++++++--- net/tap-bsd.c | 6 +++--- net/tap-linux.c | 2 +- net/tap-solaris.c | 6 +++--- net/tap.c | 3 +-- qga/commands-linux.c | 11 ++++++----- qga/commands-posix-ssh.c | 23 +++++++++++++---------- qga/commands-win32.c | 16 ++++++++-------- system/vl.c | 2 +- target/i386/sev.c | 6 ++---- target/ppc/kvm.c | 5 ++--- target/riscv/kvm/kvm-cpu.c | 11 ++++++----- tests/unit/test-smp-parse.c | 5 +---- ui/gtk.c | 2 +- ui/ui-qmp-cmds.c | 4 +--- util/vfio-helpers.c | 5 ++--- 54 files changed, 161 insertions(+), 188 deletions(-)
Signature · 1 line
2.52.0
[PULL 02/17] hw/nvram/xlnx-bbram: More idiomatic and simpler error reporting
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 '.'.
Message-ID: <[email protected]>
--- hw/nvram/xlnx-bbram.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
hw/nvram/xlnx-bbram.c +4 -14
@@ -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 */
Signature · 1 line
2.52.0
[PULL 01/17] hw/core/loader: Make load_elf_hdr() return bool, simplify caller
In reply to Markus ArmbrusterMessage-ID: <[email protected]>
--- 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(-)
include/hw/core/loader.h +3 -1
@@ -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);
hw/arm/boot.c +1 -5
@@ -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 ; }
hw/core/loader.c +6 -2
@@ -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 */
hw/riscv/spike.c +1 -9
@@ -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)
Signature · 1 line
2.52.0
[PULL 03/17] nbd/client-connection: Replace error_propagate() by assignment
In reply to Markus Armbrusterconnect_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.
Message-ID: <[email protected]>
--- nbd/client-connection.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
nbd/client-connection.c +1 -2
@@ -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));
Signature · 1 line
2.52.0
[PULL 05/17] error: Consistently name Error * objects err, and not errp
In reply to Markus ArmbrusterThis 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.
Message-ID: <[email protected]>
--- 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(-)
block/crypto.c +4 -4
@@ -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); } }
hw/acpi/ghes.c +4 -4
@@ -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 ; }
hw/ppc/spapr.c +8 -8
@@ -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);
hw/xen/xen-pvh-common.c +10 -3
@@ -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);
nbd/common.c +3 -3
@@ -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 */
Signature · 1 line
2.52.0
[PULL 06/17] error: Strip trailing '\n' from error string arguments (again)
In reply to Markus ArmbrusterTracked down with scripts/coccinelle/err-bad-newline.cocci.
Message-ID: <[email protected]>
--- hw/audio/es1370.c | 2 +- ui/gtk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/audio/es1370.c +1 -1
@@ -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,
ui/gtk.c +1 -1
@@ -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; }
Signature · 1 line
2.52.0
[PULL 04/17] error: error_free(NULL) is safe, drop unnecessary conditionals
In reply to Markus ArmbrusterMessage-ID: <[email protected]>
--- 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(-)
hw/acpi/pcihp.c +1 -3
@@ -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;
io/channel-websock.c +1 -3
@@ -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)); }
io/task.c +1 -3
@@ -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);
migration/migration.c +2 -4
@@ -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)
tests/unit/test-smp-parse.c +1 -4
@@ -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 (); }
Signature · 1 line
2.52.0
[PULL 07/17] ui: Convert to qemu_create() for simplicity and consistency
In reply to Markus ArmbrusterThe error message changes from
failed to open file 'FILENAME': REASON
to
Could not create 'FILENAME': REASON
Message-ID: <[email protected]>
--- ui/ui-qmp-cmds.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
ui/ui-qmp-cmds.c +1 -3
@@ -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 ; }
Signature · 1 line
2.52.0
[PULL 08/17] tap-solaris: Use error_setg_file_open() for better error messages
In reply to Markus ArmbrusterError 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).
Message-ID: <[email protected]>
--- net/tap-solaris.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/tap-solaris.c +3 -3
@@ -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 ){
Signature · 1 line
2.52.0
[PULL 09/17] qga: Use error_setg_file_open() for better error messages
In reply to Markus ArmbrusterError messages change from
open("FNAME"): REASON
to
Could not open 'FNAME': REASON
Message-ID: <[email protected]>
--- qga/commands-linux.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
qga/commands-linux.c +6 -5
@@ -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 ; }
Signature · 1 line
2.52.0
[PULL 10/17] net/tap: Use error_setg_file_open() for a better error message
In reply to Markus ArmbrusterThe 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.
Message-ID: <[email protected]>
--- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/tap.c +1 -2
@@ -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)) {
Signature · 1 line
2.52.0
[PULL 11/17] blkdebug: Use error_setg_file_open() for a better error message
In reply to Markus ArmbrusterThe 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.
Message-ID: <[email protected]>
--- block/blkdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blkdebug.c +1 -1
@@ -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; }
Signature · 1 line
2.52.0
[PULL 12/17] error: Use error_setg_file_open() for simplicity and consistency
In reply to Markus ArmbrusterReplace
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.
Message-ID: <[email protected]> [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(-)
hw/9pfs/9p-local.c +1 -1
@@ -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; }
hw/acpi/core.c +1 -1
@@ -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; }
hw/core/loader.c +1 -1
@@ -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 ) {
hw/pci-host/xen_igd_pt.c +1 -1
@@ -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; }
monitor/hmp-cmds.c +1 -1
@@ -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 ; }
net/dump.c +1 -1
@@ -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 ; }
net/tap-bsd.c +3 -3
@@ -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 ; } }
net/tap-linux.c +1 -1
@@ -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 ; } }
target/i386/sev.c +2 -4
@@ -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 ; }
util/vfio-helpers.c +2 -3
@@ -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;
Signature · 1 line
2.52.0
[PULL 13/17] net/slirp: Improve file open error message
In reply to Markus ArmbrusterThis 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.
Message-ID: <[email protected]>
--- net/slirp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/slirp.c +3 -1
@@ -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);
Signature · 1 line
2.52.0
[PULL 14/17] error: Use error_setg_errno() to improve error messages
In reply to Markus ArmbrusterA few error messages show numeric errno codes. Use error_setg_errno() to show human-readable text instead.
Message-ID: <[email protected]>
--- 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(-)
backends/cryptodev-lkcf.c +1 -1
@@ -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 ; }
hw/ppc/spapr.c +3 -3
@@ -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
hw/vfio/migration-multifd.c +3 -2
@@ -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 ;
migration/rdma.c +1 -2
@@ -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 ) {
net/l2tpv3.c +2 -4
@@ -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)) {
target/riscv/kvm/kvm-cpu.c +6 -5
@@ -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 ; }
Signature · 1 line
2.52.0
Re: [PULL 14/17] error: Use error_setg_errno() to improve error messages
target/riscv/kvm/kvm-cpu.c void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp) · line 2039
Quoted 10 lines · Markus Armbruster
target/riscv/kvm/kvm-cpu.c +2
-1@@ -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~
Re: [PULL 14/17] error: Use error_setg_errno() to improve error messages
Quoted 13 lines · Richard Henderson
target/riscv/kvm/kvm-cpu.c void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp) · line 2039
Quoted 10 lines · Markus Armbruster
target/riscv/kvm/kvm-cpu.c +2
-1@@ -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.
[PULL 15/17] error: Use error_setg_errno() for simplicity and consistency
In reply to Markus ArmbrusterUse 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.
Message-ID: <[email protected]>
--- 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(-)
backends/spdm-socket.c +2 -2
@@ -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 ; }
backends/tpm/tpm_emulator.c +5 -8
@@ -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; }
hw/9pfs/9p.c +1 -2
@@ -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)) {
hw/acpi/core.c +1 -2
@@ -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; }
hw/intc/openpic_kvm.c +1 -2
@@ -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;
hw/intc/xics_kvm.c +3 -2
@@ -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);
hw/remote/vfio-user-obj.c +9 -9
@@ -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; }
hw/sensor/emc141x.c +2 -2
@@ -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 ; }
hw/sensor/tmp421.c +2 -2
@@ -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 ; }
hw/smbios/smbios.c +2 -2
@@ -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 ; }
hw/virtio/vdpa-dev.c +2 -2
@@ -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;
migration/postcopy-ram.c +5 -5
@@ -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; }
net/slirp.c +3 -2
@@ -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 ; }
qga/commands-posix-ssh.c +13 -10
@@ -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; }
system/vl.c +1 -1
@@ -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 ; }
target/ppc/kvm.c +2 -3
@@ -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; }
Signature · 1 line
2.52.0
[PULL 16/17] qga/commands-win32: Use error_setg_win32() for better error messages
In reply to Markus ArmbrusterWe 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");
Message-ID: <[email protected]>
--- qga/commands-win32.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
qga/commands-win32.c +8 -8
@@ -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 )) {
Signature · 1 line
2.52.0
[PULL 17/17] block/file-win32: Improve an error message
In reply to Markus ArmbrusterTwo 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().
Message-ID: <[email protected]>
--- block/file-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/file-win32.c +1 -1
@@ -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; }
Signature · 1 line
2.52.0