Error message improvements
Subsystems (4)
v2 cover Error message improvements
v2:
* PATCH 02: New, replacing old PATCH 02 [Dave]
* PATCH 03: New, replacing one of old PATCH 09's hunks
* PATCH 12: Fix patch splitting mishap [Dave]
* PATCH 13: Fix lost argument [Dave]
Markus Armbruster (15):
error: Strip trailing '\n' from error string arguments (again) hw/usb: Convert to qemu_create() for a better error message
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 hw/scsi: Use error_setg_file_open() for a better error message hw/virtio: Use error_setg_file_open() for a better error message 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
backends/cryptodev-lkcf.c | 2 +- backends/spdm-socket.c | 4 ++-- backends/tpm/tpm_emulator.c | 13 +++++-------- block/blkdebug.c | 2 +- block/file-win32.c | 2 +- hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p.c | 3 +-- hw/acpi/core.c | 5 ++--- hw/audio/es1370.c | 2 +- hw/core/loader.c | 2 +- hw/intc/openpic_kvm.c | 3 +-- hw/intc/xics_kvm.c | 5 +++-- hw/pci-host/xen_igd_pt.c | 2 +- hw/ppc/spapr.c | 6 +++--- hw/remote/vfio-user-obj.c | 18 +++++++++--------- hw/scsi/vhost-scsi.c | 3 +-- hw/sensor/emc141x.c | 4 ++-- hw/sensor/tmp421.c | 4 ++-- hw/smbios/smbios.c | 4 ++-- hw/usb/bus.c | 5 ++--- hw/vfio/migration-multifd.c | 5 +++-- hw/virtio/vdpa-dev.c | 4 ++-- hw/virtio/vhost-vsock.c | 3 +-- migration/postcopy-ram.c | 10 +++++----- migration/rdma.c | 3 +-- monitor/hmp-cmds-target.c | 2 +- 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 ++++++----- ui/gtk.c | 2 +- ui/ui-qmp-cmds.c | 4 +--- util/vfio-helpers.c | 5 ++--- 43 files changed, 114 insertions(+), 123 deletions(-)
Signature · 1 line
2.49.0
PATCH v2 1/15 error: Strip trailing '\n' from error string arguments (again)
Tracked down with scripts/coccinelle/err-bad-newline.cocci.
--- 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.49.0
Re: [PATCH v2 01/15] error: Strip trailing '\n' from error string arguments (again)
Quoted 7 lines · Markus Armbruster
Tracked down with
scripts/coccinelle/err-bad-newline.cocci.Signed-off-by Markus Armbruster <[email protected]>--- hw/audio/es1370.c | 2 +- ui/gtk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH v2 2/15 hw/usb: Convert to qemu_create() for a better error message
In reply to Markus ArmbrusterThe error message changes from
open FILENAME failed
to
Could not create 'FILENAME': REASON
where REASON is the value of strerror(errno).
--- hw/usb/bus.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/bus.c +2 -3
@@ -259,10 +259,9 @@ static void usb_qdev_realize(DeviceState *qdev, Error **errp) }if (dev->pcap_filename) { -int fd =qemu_open_old (dev->pcap_filename, -O_CREAT |O_WRONLY |O_TRUNC |O_BINARY ,0666 ); +int fd =qemu_create (dev->pcap_filename, +O_WRONLY |O_TRUNC |O_BINARY ,0666 , errp);if (fd <0 ) { -error_setg (errp,"open %s failed" , dev->pcap_filename);usb_qdev_unrealize (qdev);return ; }
Signature · 1 line
2.49.0
Re: [PATCH v2 02/15] hw/usb: Convert to qemu_create() for a better error message
Hi Markus,
Quoted 20 lines · Markus Armbruster
The error message changes from
open FILENAME failed
to
Could not create 'FILENAME': REASON
where REASON is the value of strerror(errno).
Signed-off-by Markus Armbruster <[email protected]>--- hw/usb/bus.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)hw/usb/bus.c +0
-0
hw/usb/bus.c static void usb_qdev_realize(DeviceState *qdev, Error **errp) · line 265
Quoted 10 lines
hw/usb/bus.c +2
-3@@ -259,10 +259,9 @@ static void usb_qdev_realize(DeviceState *qdev, Error **errp) }if (dev->pcap_filename) { -int fd =qemu_open_old (dev->pcap_filename, -O_CREAT |O_WRONLY |O_TRUNC |O_BINARY ,0666 ); +int fd =qemu_create (dev->pcap_filename, +O_WRONLY |O_TRUNC |O_BINARY ,0666 , errp);if (fd <0 ) { -error_setg (errp,"open %s failed" , dev->pcap_filename);usb_qdev_unrealize (qdev);
OK, but why not update usb_qdev_realize() in the same patch?
hw/usb/bus.c static void usb_qdev_realize(DeviceState *qdev, Error **errp) · line 267
Quoted 2 lines
hw/usb/bus.c +0
-0return ; }
Similarly, I don't get why you updated this (and the following patch), without also doing the similar:
- qemu_chr_open_pipe()
- qmp_chardev_open_file_source() and qmp_screendump()
- s390_qmp_dump_skeys()
Anyhow, for this patch:
PATCH v2 3/15 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
--- 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.49.0
Re: [PATCH v2 03/15] ui: Convert to qemu_create() for simplicity and consistency
Quoted 4 lines · Markus Armbruster
The error message changes from
failed to open file 'FILENAME': REASON
Quoted 8 lines
to
Could not create 'FILENAME': REASON
Signed-off-by Markus Armbruster <[email protected]>--- ui/ui-qmp-cmds.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
PATCH v2 4/15 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).
--- 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.49.0
Re: [PATCH v2 04/15] tap-solaris: Use error_setg_file_open() for better error messages
Quoted 11 lines · Markus Armbruster
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
Quoted 7 lines
where REASON is the value of strerror(errno).
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- net/tap-solaris.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
PATCH v2 5/15 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
--- qga/commands-linux.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
qga/commands-linux.c +6 -5
@@ -1502,14 +1502,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;
@@ -1711,7 +1712,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 ;
@@ -1936,7 +1937,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 ; }
@@ -2047,7 +2048,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.49.0
Re: [PATCH v2 05/15] qga: Use error_setg_file_open() for better error messages
Quoted 6 lines · Markus Armbruster
Error messages change from
open("FNAME"): REASONto
Quoted 8 lines
Could not open 'FNAME': REASON
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Reviewed-by Kostiantyn Kostiuk <[email protected]>--- qga/commands-linux.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
PATCH v2 6/15 hw/scsi: Use error_setg_file_open() for a better error message
In reply to Markus ArmbrusterThe error message changes from
vhost-scsi: open vhost char device failed: REASON
to
Could not open '/dev/vhost-scsi': REASON
I think the exact file name is more useful to know than the file's purpose.
We could put back the "vhost-scsi: " prefix with error_prepend(). Not worth the bother.
--- hw/scsi/vhost-scsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/scsi/vhost-scsi.c +1 -2
@@ -245,8 +245,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) }else { vhostfd =open ("/dev/vhost-scsi" ,O_RDWR );if (vhostfd <0 ) { -error_setg (errp,"vhost-scsi: open vhost char device failed: %s" , -strerror (errno)); +error_setg_file_open (errp, errno,"/dev/vhost-scsi" );return ; } }
Signature · 1 line
2.49.0
Re: [PATCH v2 06/15] hw/scsi: Use error_setg_file_open() for a better error message
Quoted 11 lines · Markus Armbruster
The error message changes from
vhost-scsi: open vhost char device failed: REASON
to
Could not open '
/dev/vhost-scsi': REASONI think the exact file name is more useful to know than the file's purpose.
Quoted 8 lines
We could put back the "vhost-scsi: " prefix with
error_prepend(). Not worth the bother.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- hw/scsi/vhost-scsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH v2 7/15 hw/virtio: Use error_setg_file_open() for a better error message
In reply to Markus ArmbrusterThe error message changes from
vhost-vsock: failed to open vhost device: REASON
to
Could not open '/dev/vhost-vsock': REASON
I think the exact file name is more useful to know than the file's purpose.
--- hw/virtio/vhost-vsock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/virtio/vhost-vsock.c +1 -2
@@ -153,8 +153,7 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) }else { vhostfd =open ("/dev/vhost-vsock" ,O_RDWR );if (vhostfd <0 ) { -error_setg_errno (errp, errno, -"vhost-vsock: failed to open vhost device" ); +error_setg_file_open (errp, errno,"/dev/vhost-vsock" );return ; }
Signature · 1 line
2.49.0
Re: [PATCH v2 07/15] hw/virtio: Use error_setg_file_open() for a better error message
Quoted 8 lines · Markus Armbruster
The error message changes from
vhost-vsock: failed to open vhost device: REASON
to
Could not open '
/dev/vhost-vsock': REASON
Quoted 7 lines
I think the exact file name is more useful to know than the file's purpose.
Signed-off-by Markus Armbruster <[email protected]>--- hw/virtio/vhost-vsock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH v2 8/15 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.
--- 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.49.0
Re: [PATCH v2 08/15] net/tap: Use error_setg_file_open() for a better error message
Quoted 11 lines · Markus Armbruster
The error message changes from
tap: open vhost char device failed
to
Could not open '
/dev/vhost-net': REASONI think the exact file name is more useful to know than the file's purpose.
Quoted 7 lines
We could put back the "tap: " prefix with
error_prepend(). Not worth the bother.Signed-off-by Markus Armbruster <[email protected]>--- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH v2 9/15 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.
--- 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.49.0
Re: [PATCH v2 09/15] blkdebug: Use error_setg_file_open() for a better error message
Quoted 8 lines · Markus Armbruster
The error message changes from
Could not read blkdebug config file: REASON
to
Could not open 'FNAME': REASON
Quoted 7 lines
I think the exact file name is more useful to know than the file's purpose.
Signed-off-by Markus Armbruster <[email protected]>--- block/blkdebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 10/15 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.
--- 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-target.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
@@ -379,7 +379,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); +error_setg_file_open (errp, errno, filename);return ; }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-target.c +1 -1
@@ -331,7 +331,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
@@ -891,8 +891,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 ; }
@@ -1819,8 +1818,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.49.0
Re: [PATCH v2 10/15] error: Use error_setg_file_open() for simplicity and consistency
Quoted 17 lines · Markus Armbruster
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 witherror_prepend(). Not worth the bother.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>
Quoted 12 lines
--- 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-target.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(-)
PATCH v2 11/15 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.
--- 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.49.0
Re: [PATCH v2 11/15] net/slirp: Improve file open error message
Quoted 8 lines · Markus Armbruster
This error reports failure to create a temporary file, and
error_setg_file_open()would probably be too terse, so merely switch toerror_setg_errno()to add errno information.Signed-off-by Markus Armbruster <[email protected]>--- net/slirp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
PATCH v2 12/15 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.
--- 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
@@ -2699,9 +2699,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.49.0
Re: [PATCH v2 12/15] error: Use error_setg_errno() to improve error messages
Quoted 4 lines · Markus Armbruster
A few error messages show numeric errno codes. Use
error_setg_errno()to show human-readable text instead.Signed-off-by Markus Armbruster <[email protected]>
Quoted 8 lines
--- 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(-)
PATCH v2 13/15 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.
--- 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
@@ -619,7 +619,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.49.0
Re: [PATCH v2 13/15] error: Use error_setg_errno() for simplicity and consistency
Quoted 11 lines · Markus Armbruster
Use
error_setg_errno()instead of passing the value ofstrerror()org_strerror()toerror_setg().The separator between the error message proper and the value of
strerror()changes from " : ", "", " - ", "- " to ": " in places.Signed-off-by Markus Armbruster <[email protected]>
Thanks for the changes. The changes to vfio-user-obj.c look good to me.
Quoted 417 lines
---
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@@ -619,7 +619,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.49.0
Re: [PATCH v2 13/15] error: Use error_setg_errno() for simplicity and consistency
In reply to Markus ArmbrusterQuoted 17 lines · Markus Armbruster
Use
error_setg_errno()instead of passing the value ofstrerror()org_strerror()toerror_setg().The separator between the error message proper and the value of
strerror()changes from " : ", "", " - ", "- " to ": " in places.Signed-off-by Markus Armbruster <[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 ++--
Quoted 8 lines
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(-)
PATCH v2 14/15 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");
--- 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.49.0
Re: [PATCH v2 14/15] qga/commands-win32: Use error_setg_win32() for better error messages
Quoted 5 lines · Markus Armbruster
We include numeric
GetLastError()codes in error messages in a few places, like this:error_setg(errp, "GRIPE: %d", (int)GetLastError());
Quoted 8 lines
Show text instead, like this:
error_setg_win32(errp, GetLastError(), "GRIPE");Signed-off-by Markus Armbruster <[email protected]>--- qga/commands-win32.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
PATCH v2 15/15 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().
--- block/file-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/file-win32.c +1 -1
@@ -904,7 +904,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.49.0
Re: [PATCH v2 15/15] block/file-win32: Improve an error message
Quoted 9 lines · Markus Armbruster
Two out of three calls of
CreateFile()useerror_setg_win32()to report errors. The third useserror_setg_errno(), mappingERROR_ACCESS_DENIEDto EACCES, and everything else to EINVAL, throwing away detail. Switch it toerror_setg_win32().Signed-off-by Markus Armbruster <[email protected]>--- block/file-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Philippe Mathieu-Daudé
AppliedQuoted 6 lines · Markus Armbruster
Markus Armbruster (15):
hw/usb: Convert to
qemu_create()for a better error messagehw/scsi: Use
error_setg_file_open()for a better error message hw/virtio: Useerror_setg_file_open()for a better error message
Queued these 3, thanks.