From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524762014447477.59631717724847; Thu, 26 Apr 2018 10:00:14 -0700 (PDT) Received: from localhost ([::1]:43540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkFh-0003E4-KW for importer@patchew.org; Thu, 26 Apr 2018 13:00:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jL-Fz for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkA8-0001S9-1M for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA7-0001Re-Ol for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:27 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864862" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:26 +0100 Message-ID: <1524761612-5307-2-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 1/7] error reporting: Introduce errnoval parameter to vreport X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will allow new callers of vreport to specify that an errno value should be printed too. Update all existing callers. We use strerror rather than strerror_r because strerror_r presents portability difficulties. Replacing strerror with strerror_r (or something else) is left to the future. No functional change yet. Signed-off-by: Ian Jackson --- util/qemu-error.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/util/qemu-error.c b/util/qemu-error.c index a25d3b9..9acc4b5 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -191,12 +191,14 @@ bool enable_timestamp_msg; /* * Print a message to current monitor if we have one, else to stderr. * @report_type is the type of message: error, warning or informational. + * If @errnoval is nonnegative it is fed to strerror and printed too. * Format arguments like vsprintf(). The resulting message should be * a single phrase, with no newline or trailing punctuation. * Prepend the current location and append a newline. * It's wrong to call this in a QMP monitor. Use error_setg() there. */ -static void vreport(report_type type, const char *fmt, va_list ap) +static void vreport(report_type type, int errnoval, + const char *fmt, va_list ap) { GTimeVal tv; gchar *timestr; @@ -222,6 +224,11 @@ static void vreport(report_type type, const char *fmt,= va_list ap) } =20 error_vprintf(fmt, ap); + + if (errnoval >=3D 0) { + error_printf(": %s", strerror(errnoval)); + } + error_printf("\n"); } =20 @@ -234,7 +241,7 @@ static void vreport(report_type type, const char *fmt, = va_list ap) */ void error_vreport(const char *fmt, va_list ap) { - vreport(REPORT_TYPE_ERROR, fmt, ap); + vreport(REPORT_TYPE_ERROR, -1, fmt, ap); } =20 /* @@ -246,7 +253,7 @@ void error_vreport(const char *fmt, va_list ap) */ void warn_vreport(const char *fmt, va_list ap) { - vreport(REPORT_TYPE_WARNING, fmt, ap); + vreport(REPORT_TYPE_WARNING, -1, fmt, ap); } =20 /* @@ -259,7 +266,7 @@ void warn_vreport(const char *fmt, va_list ap) */ void info_vreport(const char *fmt, va_list ap) { - vreport(REPORT_TYPE_INFO, fmt, ap); + vreport(REPORT_TYPE_INFO, -1, fmt, ap); } =20 /* @@ -274,7 +281,7 @@ void error_report(const char *fmt, ...) va_list ap; =20 va_start(ap, fmt); - vreport(REPORT_TYPE_ERROR, fmt, ap); + vreport(REPORT_TYPE_ERROR, -1, fmt, ap); va_end(ap); } =20 @@ -290,7 +297,7 @@ void warn_report(const char *fmt, ...) va_list ap; =20 va_start(ap, fmt); - vreport(REPORT_TYPE_WARNING, fmt, ap); + vreport(REPORT_TYPE_WARNING, -1, fmt, ap); va_end(ap); } =20 @@ -307,6 +314,6 @@ void info_report(const char *fmt, ...) va_list ap; =20 va_start(ap, fmt); - vreport(REPORT_TYPE_INFO, fmt, ap); + vreport(REPORT_TYPE_INFO, -1, fmt, ap); va_end(ap); } --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15247625124541003.8526882274485; Thu, 26 Apr 2018 10:08:32 -0700 (PDT) Received: from localhost ([::1]:43609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkNj-0001bC-Di for importer@patchew.org; Thu, 26 Apr 2018 13:08:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jN-Gg for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkA8-0001SN-Mz for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA8-0001Rn-DX for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:28 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864866" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:27 +0100 Message-ID: <1524761612-5307-3-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 2/7] error reporting: Provide error_report_errno (and error_vreport_errno) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will let us replace a lot of open coded calls to perror, strerror, etc. No callers yet so no functional change. Signed-off-by: Ian Jackson --- include/qemu/error-report.h | 2 ++ util/qemu-error.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index e1c8ae1..2b29678 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -37,10 +37,12 @@ void error_printf_unless_qmp(const char *fmt, ...) GCC_= FMT_ATTR(1, 2); void error_set_progname(const char *argv0); =20 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void error_vreport_errno(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); =20 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +void error_report_errno(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 diff --git a/util/qemu-error.c b/util/qemu-error.c index 9acc4b5..428c762 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -245,6 +245,18 @@ void error_vreport(const char *fmt, va_list ap) } =20 /* + * Print an error message to current monitor if we have one, else to stder= r. + * Format arguments like vsprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errno) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_vreport_errno(const char *fmt, va_list ap) +{ + vreport(REPORT_TYPE_ERROR, errno, fmt, ap); +} + +/* * Print a warning message to current monitor if we have one, else to stde= rr. * Format arguments like vsprintf(). The resulting message should be * a single phrase, with no newline or trailing punctuation. @@ -286,6 +298,22 @@ void error_report(const char *fmt, ...) } =20 /* + * Print an error message to current monitor if we have one, else to stder= r. + * Format arguments like sprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errno) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_report_errno(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vreport(REPORT_TYPE_ERROR, errno, fmt, ap); + va_end(ap); +} + +/* * Print a warning message to current monitor if we have one, else to stde= rr. * Format arguments like sprintf(). The resulting message should be a * single phrase, with no newline or trailing punctuation. --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524761962193648.2392175195369; Thu, 26 Apr 2018 09:59:22 -0700 (PDT) Received: from localhost ([::1]:43539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkEr-0002FB-8b for importer@patchew.org; Thu, 26 Apr 2018 12:59:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jT-IC for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkAA-0001Sm-6I for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA9-0001Rn-Mw for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:30 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864870" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:28 +0100 Message-ID: <1524761612-5307-4-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 3/7] error reporting: Use error_report_errno in obvious places X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is the result of git-grep -l 'error_report.*strerror' | xargs perl -p -i~ ../t with ../t containing s{error_report\("(.*): \%s"(, .*)?, strerror\(errno\)\)\;}{error_report_e= rrno\("$1"$2)\;} Since this is an automatically generated patch, it does not contain any cleanups of the occasional idiosyncratic messages. That is left to the future. No functional change, since error_report_errno does exactly what this previous open-coded pattern does. Signed-off-by: Ian Jackson --- audio/wavcapture.c | 2 +- hw/i386/xen/xen-hvm.c | 2 +- hw/tpm/tpm_emulator.c | 2 +- hw/xen/xen_pt_load_rom.c | 4 ++-- migration/postcopy-ram.c | 12 ++++++------ net/tap-linux.c | 2 +- os-posix.c | 8 ++++---- qemu-nbd.c | 4 ++-- scsi/qemu-pr-helper.c | 4 ++-- slirp/misc.c | 4 ++-- util/osdep.c | 2 +- vl.c | 6 +++--- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/audio/wavcapture.c b/audio/wavcapture.c index cf31ed6..7046365 100644 --- a/audio/wavcapture.c +++ b/audio/wavcapture.c @@ -66,7 +66,7 @@ static void wav_destroy (void *opaque) } doclose: if (fclose (wav->f)) { - error_report("wav_destroy: fclose failed: %s", strerror(errno)= ); + error_report_errno("wav_destroy: fclose failed"); } } =20 diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index caa563b..2778c92 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -414,7 +414,7 @@ go_physmap: (start_addr + size - 1) >> TARGET_PAGE_= BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); if (rc) { - error_report("pin_memory_cacheattr failed: %s", strerror(errno)); + error_report_errno("pin_memory_cacheattr failed"); } return xen_save_physmap(state, physmap); } diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 6418ef0..4345c1d 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -190,7 +190,7 @@ static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) { if (tpm_emulator_ctrlcmd(tpm_emu, CMD_GET_CAPABILITY, &tpm_emu->caps, 0, sizeof(tpm_emu->caps)) < 0= ) { - error_report("tpm-emulator: probing failed : %s", strerror(errno)); + error_report_errno("tpm-emulator: probing failed "); return -1; } =20 diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c index 71063c4..bbfe423 100644 --- a/hw/xen/xen_pt_load_rom.c +++ b/hw/xen/xen_pt_load_rom.c @@ -43,12 +43,12 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, st= ruct Object *owner, fp =3D fopen(rom_file, "r+"); if (fp =3D=3D NULL) { if (errno !=3D ENOENT) { - error_report("pci-assign: Cannot open %s: %s", rom_file, strer= ror(errno)); + error_report_errno("pci-assign: Cannot open %s", rom_file); } return NULL; } if (fstat(fileno(fp), &st) =3D=3D -1) { - error_report("pci-assign: Cannot stat %s: %s", rom_file, strerror(= errno)); + error_report_errno("pci-assign: Cannot stat %s", rom_file); goto close_rom; } =20 diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 8ceeaa2..6bfe002 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -406,14 +406,14 @@ bool postcopy_ram_supported_by_host(MigrationIncoming= State *mis) reg_struct.mode =3D UFFDIO_REGISTER_MODE_MISSING; =20 if (ioctl(ufd, UFFDIO_REGISTER, ®_struct)) { - error_report("%s userfault register: %s", __func__, strerror(errno= )); + error_report_errno("%s userfault register", __func__); goto out; } =20 range_struct.start =3D (uintptr_t)testarea; range_struct.len =3D pagesize; if (ioctl(ufd, UFFDIO_UNREGISTER, &range_struct)) { - error_report("%s userfault unregister: %s", __func__, strerror(err= no)); + error_report_errno("%s userfault unregister", __func__); goto out; } =20 @@ -543,7 +543,7 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingStat= e *mis) =20 if (enable_mlock) { if (os_mlock() < 0) { - error_report("mlock: %s", strerror(errno)); + error_report_errno("mlock"); /* * It doesn't feel right to fail at this point, we have a valid * VM state. @@ -624,7 +624,7 @@ static int ram_block_enable_notify(const char *block_na= me, void *host_addr, =20 /* Now tell our userfault_fd that it's responsible for this area */ if (ioctl(mis->userfault_fd, UFFDIO_REGISTER, ®_struct)) { - error_report("%s userfault register: %s", __func__, strerror(errno= )); + error_report_errno("%s userfault register", __func__); return -1; } if (!(reg_struct.ioctls & ((__u64)1 << _UFFDIO_COPY))) { @@ -876,7 +876,7 @@ static void *postcopy_ram_fault_thread(void *opaque) =20 poll_result =3D poll(pfd, pfd_len, -1 /* Wait forever */); if (poll_result =3D=3D -1) { - error_report("%s: userfault poll: %s", __func__, strerror(errn= o)); + error_report_errno("%s: userfault poll", __func__); break; } =20 @@ -1199,7 +1199,7 @@ void *postcopy_get_tmp_page(MigrationIncomingState *m= is) MAP_ANONYMOUS, -1, 0); if (mis->postcopy_tmp_page =3D=3D MAP_FAILED) { mis->postcopy_tmp_page =3D NULL; - error_report("%s: %s", __func__, strerror(errno)); + error_report_errno("%s", __func__); return NULL; } } diff --git a/net/tap-linux.c b/net/tap-linux.c index 535b1dd..897e788 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -152,7 +152,7 @@ int tap_probe_vnet_hdr(int fd) struct ifreq ifr; =20 if (ioctl(fd, TUNGETIFF, &ifr) !=3D 0) { - error_report("TUNGETIFF ioctl() failed: %s", strerror(errno)); + error_report_errno("TUNGETIFF ioctl() failed"); return 0; } =20 diff --git a/os-posix.c b/os-posix.c index 24eb700..e6edb7d 100644 --- a/os-posix.c +++ b/os-posix.c @@ -125,7 +125,7 @@ void os_set_proc_name(const char *s) /* Could rewrite argv[0] too, but that's a bit more complicated. This simple way is enough for `top'. */ if (prctl(PR_SET_NAME, name)) { - error_report("unable to change process name: %s", strerror(errno)); + error_report_errno("unable to change process name"); exit(1); } #else @@ -247,7 +247,7 @@ static void change_root(void) exit(1); } if (chdir("/")) { - error_report("not able to chdir to /: %s", strerror(errno)); + error_report_errno("not able to chdir to /"); exit(1); } } @@ -309,7 +309,7 @@ void os_setup_post(void) =20 if (daemonize) { if (chdir("/")) { - error_report("not able to chdir to /: %s", strerror(errno)); + error_report_errno("not able to chdir to /"); exit(1); } TFR(fd =3D qemu_open("/dev/null", O_RDWR)); @@ -383,7 +383,7 @@ int os_mlock(void) =20 ret =3D mlockall(MCL_CURRENT | MCL_FUTURE); if (ret < 0) { - error_report("mlockall: %s", strerror(errno)); + error_report_errno("mlockall"); } =20 return ret; diff --git a/qemu-nbd.c b/qemu-nbd.c index 0af0560..47b6957 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -847,7 +847,7 @@ int main(int argc, char **argv) */ pid =3D fork(); if (pid < 0) { - error_report("Failed to fork: %s", strerror(errno)); + error_report_errno("Failed to fork"); exit(EXIT_FAILURE); } else if (pid =3D=3D 0) { close(stderr_fd[0]); @@ -857,7 +857,7 @@ int main(int argc, char **argv) old_stderr =3D dup(STDERR_FILENO); dup2(stderr_fd[1], STDERR_FILENO); if (ret < 0) { - error_report("Failed to daemonize: %s", strerror(errno)); + error_report_errno("Failed to daemonize"); exit(EXIT_FAILURE); } =20 diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index d0f8317..663a8a8 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -1085,7 +1085,7 @@ int main(int argc, char **argv) =20 if (daemonize) { if (daemon(0, 0) < 0) { - error_report("Failed to daemonize: %s", strerror(errno)); + error_report_errno("Failed to daemonize"); exit(EXIT_FAILURE); } } @@ -1095,7 +1095,7 @@ int main(int argc, char **argv) =20 #ifdef CONFIG_LIBCAP if (drop_privileges() < 0) { - error_report("Failed to drop privileges: %s", strerror(errno)); + error_report_errno("Failed to drop privileges"); exit(EXIT_FAILURE); } #endif diff --git a/slirp/misc.c b/slirp/misc.c index 260187b..11a8bd1 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -111,7 +111,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty) if ((s =3D qemu_socket(AF_INET, SOCK_STREAM, 0)) < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || listen(s, 1) < 0) { - error_report("Error: inet socket: %s", strerror(errno)); + error_report_errno("Error: inet socket"); if (s >=3D 0) { closesocket(s); } @@ -123,7 +123,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty) pid =3D fork(); switch(pid) { case -1: - error_report("Error: fork failed: %s", strerror(errno)); + error_report_errno("Error: fork failed"); close(s); return 0; =20 diff --git a/util/osdep.c b/util/osdep.c index a73de0e..b78b98b 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -89,7 +89,7 @@ static int qemu_mprotect__osdep(void *addr, size_t size, = int prot) return 0; #else if (mprotect(addr, size, prot)) { - error_report("%s: mprotect failed: %s", __func__, strerror(errno)); + error_report_errno("%s: mprotect failed", __func__); return -1; } return 0; diff --git a/vl.c b/vl.c index d37e857..2f09210 100644 --- a/vl.c +++ b/vl.c @@ -1194,7 +1194,7 @@ static int parse_add_fd(void *opaque, QemuOpts *opts,= Error **errp) } #endif if (dupfd =3D=3D -1) { - error_report("error duplicating fd: %s", strerror(errno)); + error_report_errno("error duplicating fd"); return -1; } =20 @@ -4069,7 +4069,7 @@ int main(int argc, char **argv, char **envp) } vmstate_dump_file =3D fopen(optarg, "w"); if (vmstate_dump_file =3D=3D NULL) { - error_report("open %s: %s", optarg, strerror(errno)); + error_report_errno("open %s", optarg); exit(1); } break; @@ -4094,7 +4094,7 @@ int main(int argc, char **argv, char **envp) rcu_disable_atfork(); =20 if (pid_file && qemu_create_pidfile(pid_file) !=3D 0) { - error_report("could not acquire pid file: %s", strerror(errno)); + error_report_errno("could not acquire pid file"); exit(1); } =20 --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524761857638452.71244909266875; Thu, 26 Apr 2018 09:57:37 -0700 (PDT) Received: from localhost ([::1]:43526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkD8-0000bQ-Oy for importer@patchew.org; Thu, 26 Apr 2018 12:57:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jS-Hr for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkAB-0001T7-4W for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkAA-0001Rn-PB for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:31 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864868" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:29 +0100 Message-ID: <1524761612-5307-5-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 4/7] error reporting: Fix some error messages to use ":" rather than ", " X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is the result of git-grep -l 'error_report.*strerror' | xargs perl -p -i~ ../t with ../t containing s{error_report\("(.*), \%s"(, .*)?, strerror\(errno\)\)\;}{error_report_e= rrno\("$1"$2)\;} Note the comma here ^ which is a one-character difference from the previous patch. The effect is that a lot of messages which used to say something went wrong, now say something went wrong: And of course we remove a lot of open-coded calls. Signed-off-by: Ian Jackson --- block/sheepdog.c | 16 ++++++++-------- scsi/qemu-pr-helper.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 387f59c..70e4bba 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -603,13 +603,13 @@ static coroutine_fn int send_co_req(int sockfd, Sheep= dogReq *hdr, void *data, =20 ret =3D qemu_co_send(sockfd, hdr, sizeof(*hdr)); if (ret !=3D sizeof(*hdr)) { - error_report("failed to send a req, %s", strerror(errno)); + error_report_errno("failed to send a req"); return -errno; } =20 ret =3D qemu_co_send(sockfd, data, *wlen); if (ret !=3D *wlen) { - error_report("failed to send a req, %s", strerror(errno)); + error_report_errno("failed to send a req"); return -errno; } =20 @@ -660,7 +660,7 @@ static coroutine_fn void do_co_req(void *opaque) =20 ret =3D qemu_co_recv(sockfd, hdr, sizeof(*hdr)); if (ret !=3D sizeof(*hdr)) { - error_report("failed to get a rsp, %s", strerror(errno)); + error_report_errno("failed to get a rsp"); ret =3D -errno; goto out; } @@ -672,7 +672,7 @@ static coroutine_fn void do_co_req(void *opaque) if (*rlen) { ret =3D qemu_co_recv(sockfd, data, *rlen); if (ret !=3D *rlen) { - error_report("failed to get the data, %s", strerror(errno)); + error_report_errno("failed to get the data"); ret =3D -errno; goto out; } @@ -809,7 +809,7 @@ static void coroutine_fn aio_read_response(void *opaque) /* read a header */ ret =3D qemu_co_recv(fd, &rsp, sizeof(rsp)); if (ret !=3D sizeof(rsp)) { - error_report("failed to get the header, %s", strerror(errno)); + error_report_errno("failed to get the header"); goto err; } =20 @@ -851,7 +851,7 @@ static void coroutine_fn aio_read_response(void *opaque) ret =3D qemu_co_recvv(fd, acb->qiov->iov, acb->qiov->niov, aio_req->iov_offset, rsp.data_length); if (ret !=3D rsp.data_length) { - error_report("failed to get the data, %s", strerror(errno)); + error_report_errno("failed to get the data"); goto err; } break; @@ -1362,14 +1362,14 @@ static void coroutine_fn add_aio_request(BDRVSheepd= ogState *s, AIOReq *aio_req, /* send a header */ ret =3D qemu_co_send(s->fd, &hdr, sizeof(hdr)); if (ret !=3D sizeof(hdr)) { - error_report("failed to send a req, %s", strerror(errno)); + error_report_errno("failed to send a req"); goto out; } =20 if (wlen) { ret =3D qemu_co_sendv(s->fd, iov, niov, aio_req->iov_offset, wlen); if (ret !=3D wlen) { - error_report("failed to send a data, %s", strerror(errno)); + error_report_errno("failed to send a data"); } } out: diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 663a8a8..ff56313 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -118,12 +118,12 @@ static void write_pidfile(void) =20 pidfd =3D qemu_open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR); if (pidfd =3D=3D -1) { - error_report("Cannot open pid file, %s", strerror(errno)); + error_report_errno("Cannot open pid file"); exit(EXIT_FAILURE); } =20 if (lockf(pidfd, F_TLOCK, 0)) { - error_report("Cannot lock pid file, %s", strerror(errno)); + error_report_errno("Cannot lock pid file"); goto fail; } if (ftruncate(pidfd, 0)) { --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524762625598188.97093821731812; Thu, 26 Apr 2018 10:10:25 -0700 (PDT) Received: from localhost ([::1]:43614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkPO-0002nN-M9 for importer@patchew.org; Thu, 26 Apr 2018 13:10:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jM-G3 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkA9-0001Sa-LE for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA8-0001Re-Go for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:29 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864871" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:30 +0100 Message-ID: <1524761612-5307-6-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 5/7] error reporting: Provide error_report_errnoval (and error_vreport_errnoval) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will let us replace more open coded calls to error_report and strerror. I have chosen to provide all of error_report_errno error_vreport_errno error_report_errnoval error_vreport_errnoval because the former are much more common, and deserve a short spelling; whereas there are still at least 30-40 potential callers of the latter. No callers yet so no functional change. Signed-off-by: Ian Jackson --- include/qemu/error-report.h | 5 +++++ util/qemu-error.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 2b29678..5178173 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -46,6 +46,11 @@ void error_report_errno(const char *fmt, ...) GCC_FMT_AT= TR(1, 2); void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); =20 +void error_vreport_errnoval(int errnoval, + const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0= ); +void error_report_errnoval(int errnoval, + const char *fmt, ...) GCC_FMT_ATTR(2, 3); + const char *error_get_progname(void); extern bool enable_timestamp_msg; =20 diff --git a/util/qemu-error.c b/util/qemu-error.c index 428c762..8add1f3 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -257,6 +257,18 @@ void error_vreport_errno(const char *fmt, va_list ap) } =20 /* + * Print an error message to current monitor if we have one, else to stder= r. + * Format arguments like vsprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errnoval) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_vreport_errnoval(int errnoval, const char *fmt, va_list ap) +{ + vreport(REPORT_TYPE_ERROR, errnoval, fmt, ap); +} + +/* * Print a warning message to current monitor if we have one, else to stde= rr. * Format arguments like vsprintf(). The resulting message should be * a single phrase, with no newline or trailing punctuation. @@ -314,6 +326,22 @@ void error_report_errno(const char *fmt, ...) } =20 /* + * Print an error message to current monitor if we have one, else to stder= r. + * Format arguments like sprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errnoval) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_report_errnoval(int errnoval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vreport(REPORT_TYPE_ERROR, errnoval, fmt, ap); + va_end(ap); +} + +/* * Print a warning message to current monitor if we have one, else to stde= rr. * Format arguments like sprintf(). The resulting message should be a * single phrase, with no newline or trailing punctuation. --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524762206643729.4370007685188; Thu, 26 Apr 2018 10:03:26 -0700 (PDT) Received: from localhost ([::1]:43562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkIj-0005qT-MV for importer@patchew.org; Thu, 26 Apr 2018 13:03:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jl-Tk for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkAB-0001T1-0q for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkAA-0001Re-Fg for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:30 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864877" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:31 +0100 Message-ID: <1524761612-5307-7-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 6/7] error reporting: Use error_report_errnoval in obvious places X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is the result of git-grep -l 'error_report.*strerror' | xargs perl -p -i~ ../t with ../t containing s{error_report\("(.*): \%s"(, .*)?, strerror\((.*)\)\)\;}{error_report_er= rnoval\($3, "$1"$2)\;} Like the previous patch to use error_report_errno, this patch does not contain any cleanups of the occasional idiosyncratic messages. That is left to the future. No functional change, since error_report_errnoval does exactly what this previous open-coded pattern does. Signed-off-by: Ian Jackson --- block/nvme.c | 2 +- block/rbd.c | 2 +- cpus.c | 2 +- hw/ppc/spapr_hcall.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 6 +++--- hw/s390x/s390-virtio-ccw.c | 2 +- hw/scsi/vhost-scsi.c | 2 +- hw/scsi/vhost-user-scsi.c | 2 +- migration/migration.c | 2 +- qemu-img.c | 10 +++++----- qemu-io-cmds.c | 4 ++-- qemu-nbd.c | 6 +++--- target/arm/kvm64.c | 4 ++-- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index c4f3a7b..d479ea9 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1144,7 +1144,7 @@ static void nvme_register_buf(BlockDriverState *bs, v= oid *host, size_t size) /* FIXME: we may run out of IOVA addresses after repeated * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_un= map * doesn't reclaim addresses for fixed mappings. */ - error_report("nvme_register_buf failed: %s", strerror(-ret)); + error_report_errnoval(-ret, "nvme_register_buf failed"); } } =20 diff --git a/block/rbd.c b/block/rbd.c index c9359d0..e7b5d15 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1020,7 +1020,7 @@ static int qemu_rbd_snap_create(BlockDriverState *bs, =20 r =3D rbd_snap_create(s->image, sn_info->name); if (r < 0) { - error_report("failed to create snap: %s", strerror(-r)); + error_report_errnoval(-r, "failed to create snap"); return r; } =20 diff --git a/cpus.c b/cpus.c index 38eba8b..f62b3a8 100644 --- a/cpus.c +++ b/cpus.c @@ -1200,7 +1200,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) =20 r =3D kvm_init_vcpu(cpu); if (r < 0) { - error_report("kvm_init_vcpu failed: %s", strerror(-r)); + error_report_errnoval(-r, "kvm_init_vcpu failed"); exit(1); } =20 diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 16bccdd..112156f 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -693,7 +693,7 @@ static void do_push_sregs_to_kvm_pr(CPUState *cs, run_o= n_cpu_data data) =20 ret =3D kvmppc_put_books_sregs(POWERPC_CPU(cs)); if (ret < 0) { - error_report("failed to push sregs to KVM: %s", strerror(-ret)); + error_report_errnoval(-ret, "failed to push sregs to KVM"); exit(1); } } diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c index 480551c..fea2bce 100644 --- a/hw/s390x/s390-stattrib-kvm.c +++ b/hw/s390x/s390-stattrib-kvm.c @@ -52,7 +52,7 @@ static int kvm_s390_stattrib_read_helper(S390StAttribStat= e *sa, =20 r =3D kvm_vm_ioctl(kvm_state, KVM_S390_GET_CMMA_BITS, &clog); if (r < 0) { - error_report("KVM_S390_GET_CMMA_BITS failed: %s", strerror(-r)); + error_report_errnoval(-r, "KVM_S390_GET_CMMA_BITS failed"); return r; } =20 @@ -119,7 +119,7 @@ static void kvm_s390_stattrib_synchronize(S390StAttribS= tate *sa) clog.values =3D (uint64_t)(sas->incoming_buffer + cx); r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); if (r) { - error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); + error_report_errnoval(-r, "KVM_S390_SET_CMMA_BITS failed"); return; } } @@ -129,7 +129,7 @@ static void kvm_s390_stattrib_synchronize(S390StAttribS= tate *sa) clog.values =3D (uint64_t)(sas->incoming_buffer + cx); r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); if (r) { - error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); + error_report_errnoval(-r, "KVM_S390_SET_CMMA_BITS failed"); } } g_free(sas->incoming_buffer); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 435f7c9..d580b48 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -228,7 +228,7 @@ static int gtod_load(QEMUFile *f, void *opaque, int ver= sion_id) =20 r =3D s390_set_clock(&tod_high, &tod_low); if (r) { - error_report("Unable to set KVM guest TOD clock: %s", strerror(-r)= ); + error_report_errnoval(-r, "Unable to set KVM guest TOD clock"); } =20 return r; diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 9c1bea8..354aaef 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -123,7 +123,7 @@ static void vhost_scsi_set_status(VirtIODevice *vdev, u= int8_t val) =20 ret =3D vhost_scsi_start(s); if (ret < 0) { - error_report("unable to start vhost-scsi: %s", strerror(-ret)); + error_report_errnoval(-ret, "unable to start vhost-scsi"); exit(1); } } else { diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index 9389ed4..aa027e1 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -52,7 +52,7 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev= , uint8_t status) =20 ret =3D vhost_scsi_common_start(vsc); if (ret < 0) { - error_report("unable to start vhost-user-scsi: %s", strerror(-= ret)); + error_report_errnoval(-ret, "unable to start vhost-user-scsi"); exit(1); } } else { diff --git a/migration/migration.c b/migration/migration.c index 0bdb28e..2732519 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -403,7 +403,7 @@ static void process_incoming_migration_co(void *opaque) =20 migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); - error_report("load of migration failed: %s", strerror(-ret)); + error_report_errnoval(-ret, "load of migration failed"); qemu_fclose(mis->from_src_file); if (multifd_load_cleanup(&local_err) !=3D 0) { error_report_err(local_err); diff --git a/qemu-img.c b/qemu-img.c index 855fa52..3527455 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -820,7 +820,7 @@ static int img_check(int argc, char **argv) =20 if (ret || check->check_errors) { if (ret) { - error_report("Check failed: %s", strerror(-ret)); + error_report_errnoval(-ret, "Check failed"); } else { error_report("Check failed"); } @@ -2831,7 +2831,7 @@ static int img_map(int argc, char **argv) ret =3D get_block_status(bs, offset, n, &next); =20 if (ret < 0) { - error_report("Could not read file metadata: %s", strerror(-ret= )); + error_report_errnoval(-ret, "Could not read file metadata"); goto out; } =20 @@ -3730,7 +3730,7 @@ static int img_amend(int argc, char **argv) ret =3D bdrv_amend_options(bs, opts, &amend_status_cb, NULL); qemu_progress_print(100.f, 0); if (ret < 0) { - error_report("Error while amending options: %s", strerror(-ret)); + error_report_errnoval(-ret, "Error while amending options"); goto out; } =20 @@ -3770,7 +3770,7 @@ typedef struct BenchData { static void bench_undrained_flush_cb(void *opaque, int ret) { if (ret < 0) { - error_report("Failed flush request: %s", strerror(-ret)); + error_report_errnoval(-ret, "Failed flush request"); exit(EXIT_FAILURE); } } @@ -3781,7 +3781,7 @@ static void bench_cb(void *opaque, int ret) BlockAIOCB *acb; =20 if (ret < 0) { - error_report("Failed request: %s", strerror(-ret)); + error_report_errnoval(-ret, "Failed request"); exit(EXIT_FAILURE); } =20 diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 9b3cd00..379a1ee 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1862,14 +1862,14 @@ static int map_f(BlockBackend *blk, int argc, char = **argv) offset =3D 0; bytes =3D blk_getlength(blk); if (bytes < 0) { - error_report("Failed to query image length: %s", strerror(-bytes)); + error_report_errnoval(-bytes, "Failed to query image length"); return 0; } =20 while (bytes) { ret =3D map_is_allocated(blk_bs(blk), offset, bytes, &num); if (ret < 0) { - error_report("Failed to get allocation status: %s", strerror(-= ret)); + error_report_errnoval(-ret, "Failed to get allocation status"); return 0; } else if (!num) { error_report("Unexpected end of image"); diff --git a/qemu-nbd.c b/qemu-nbd.c index 47b6957..70cb564 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -179,7 +179,7 @@ static int find_partition(BlockBackend *blk, int partit= ion, =20 ret =3D blk_pread(blk, 0, data, sizeof(data)); if (ret < 0) { - error_report("error while reading: %s", strerror(-ret)); + error_report_errnoval(-ret, "error while reading"); exit(EXIT_FAILURE); } =20 @@ -202,7 +202,7 @@ static int find_partition(BlockBackend *blk, int partit= ion, ret =3D blk_pread(blk, mbr[i].start_sector_abs * MBR_SIZE, data1, sizeof(data1)); if (ret < 0) { - error_report("error while reading: %s", strerror(-ret)); + error_report_errnoval(-ret, "error while reading"); exit(EXIT_FAILURE); } =20 @@ -1021,7 +1021,7 @@ int main(int argc, char **argv) =20 ret =3D pthread_create(&client_thread, NULL, nbd_client_thread, de= vice); if (ret !=3D 0) { - error_report("Failed to create client thread: %s", strerror(re= t)); + error_report_errnoval(ret, "Failed to create client thread"); exit(EXIT_FAILURE); } } else { diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index e0b8246..64b47b6 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -387,13 +387,13 @@ static bool kvm_arm_pmu_set_attr(CPUState *cs, struct= kvm_device_attr *attr) =20 err =3D kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); if (err !=3D 0) { - error_report("PMU: KVM_HAS_DEVICE_ATTR: %s", strerror(-err)); + error_report_errnoval(-err, "PMU: KVM_HAS_DEVICE_ATTR"); return false; } =20 err =3D kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); if (err !=3D 0) { - error_report("PMU: KVM_SET_DEVICE_ATTR: %s", strerror(-err)); + error_report_errnoval(-err, "PMU: KVM_SET_DEVICE_ATTR"); return false; } =20 --=20 2.1.4 From nobody Wed Oct 29 06:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524761952670855.2170600426376; Thu, 26 Apr 2018 09:59:12 -0700 (PDT) Received: from localhost ([::1]:43536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkEX-000207-MS for importer@patchew.org; Thu, 26 Apr 2018 12:59:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jR-HY for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkAA-0001Sr-6s for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA9-0001Re-Ss for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:30 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864872" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:32 +0100 Message-ID: <1524761612-5307-8-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 7/7] error reporting: HACKING: Say to use error_report_errno X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Ian Jackson --- HACKING | 1 + 1 file changed, 1 insertion(+) diff --git a/HACKING b/HACKING index 4125c97..95563a3 100644 --- a/HACKING +++ b/HACKING @@ -189,6 +189,7 @@ error_report() or error_vreport() from error-report.h. = This ensures the error is reported in the right place (current monitor or stderr), and in a uniform format. =20 +Use error_report_errno rather than open-coding calls to strerror(). Use error_printf() & friends to print additional information. =20 error_report() prints the current location. In certain common cases --=20 2.1.4