qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] misc: Improve error reporting on Windows
@ 2020-02-28 10:07 Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 1/4] chardev: Improve error report by calling error_setg_win32() Philippe Mathieu-Daudé
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-28 10:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Roth, Markus Armbruster,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau, Philippe Mathieu-Daudé

Few patches to improve bug reports on Windows.
(i.e. https://bugs.launchpad.net/qemu/+bug/1657841)

Since v2:
- Remove changes in functions using fprintf()
  (util/oslib-win32.c is no more modified)
- Do not remove slog() call in qmp_guest_shutdown()

Since v1:
- Rebase an old patch from Alistair to use error_report()
  as suggested by Markus
- Fix other uses in util/osdep.c and QEMU guest-agent

Philippe Mathieu-Daudé (4):
  chardev: Improve error report by calling error_setg_win32()
  util/osdep: Improve error report by calling error_setg_win32()
  qga: Improve error report by calling error_setg_win32()
  qga: Fix a memory leak

 chardev/char-pipe.c  | 2 +-
 chardev/char-win.c   | 2 +-
 qga/channel-win32.c  | 7 ++++---
 qga/commands-win32.c | 8 +++++---
 util/osdep.c         | 4 ++--
 5 files changed, 13 insertions(+), 10 deletions(-)

-- 
2.21.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/4] chardev: Improve error report by calling error_setg_win32()
  2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
@ 2020-02-28 10:07 ` Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 2/4] util/osdep: " Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-28 10:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P . Berrangé, Michael Roth, Markus Armbruster,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau, Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 chardev/char-pipe.c | 2 +-
 chardev/char-win.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c
index 94d714ffcd..fd12c9e63b 100644
--- a/chardev/char-pipe.c
+++ b/chardev/char-pipe.c
@@ -70,7 +70,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
                               MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);
     g_free(openname);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateNamedPipe");
         s->file = NULL;
         goto fail;
     }
diff --git a/chardev/char-win.c b/chardev/char-win.c
index 34825f683d..d4fb44c4dc 100644
--- a/chardev/char-win.c
+++ b/chardev/char-win.c
@@ -96,7 +96,7 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                       OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateFile");
         s->file = NULL;
         goto fail;
     }
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/4] util/osdep: Improve error report by calling error_setg_win32()
  2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 1/4] chardev: Improve error report by calling error_setg_win32() Philippe Mathieu-Daudé
@ 2020-02-28 10:07 ` Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 3/4] qga: " Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-28 10:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Roth, Markus Armbruster,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau, Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3: Remove change in socket_init() which uses fprintf()
---
 util/osdep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/osdep.c b/util/osdep.c
index f7d06050f7..4829c07ff6 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -82,8 +82,8 @@ static int qemu_mprotect__osdep(void *addr, size_t size, int prot)
     DWORD old_protect;
 
     if (!VirtualProtect(addr, size, prot, &old_protect)) {
-        error_report("%s: VirtualProtect failed with error code %ld",
-                     __func__, GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        error_report("%s: VirtualProtect failed: %s", __func__, emsg);
         return -1;
     }
     return 0;
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 3/4] qga: Improve error report by calling error_setg_win32()
  2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 1/4] chardev: Improve error report by calling error_setg_win32() Philippe Mathieu-Daudé
  2020-02-28 10:07 ` [PATCH v3 2/4] util/osdep: " Philippe Mathieu-Daudé
@ 2020-02-28 10:07 ` Philippe Mathieu-Daudé
  2020-02-28 10:23   ` Marc-André Lureau
  2020-02-28 10:07 ` [PATCH v3 4/4] qga: Fix a memory leak Philippe Mathieu-Daudé
  2020-03-02 10:08 ` [PATCH v3 0/4] misc: Improve error reporting on Windows Markus Armbruster
  4 siblings, 1 reply; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-28 10:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Roth, Markus Armbruster,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau, Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v3: Keep slog() in qmp_guest_shutdown() (Marc-André)
---
 qga/channel-win32.c  | 3 ++-
 qga/commands-win32.c | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index c86f4388db..99648c95b6 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -308,7 +308,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
     }
 
     if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
-        g_critical("error setting timeout for com port: %lu",GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        g_critical("error setting timeout for com port: %s", emsg);
         CloseHandle(c->handle);
         return false;
     }
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2461fd19bf..9c744d6405 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -315,8 +315,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
     }
 
     if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
-        slog("guest-shutdown failed: %lu", GetLastError());
-        error_setg(errp, QERR_UNDEFINED_ERROR);
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        slog("guest-shutdown failed: %s", emsg);
+        error_setg_win32(errp, GetLastError(), "guest-shutdown failed");
     }
 }
 
@@ -1319,7 +1320,8 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
     DWORD ret = 0;
 
     if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
-        slog("failed to suspend guest, %lu", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        slog("failed to suspend guest: %s", emsg);
         ret = -1;
     }
     g_free(mode);
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 4/4] qga: Fix a memory leak
  2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2020-02-28 10:07 ` [PATCH v3 3/4] qga: " Philippe Mathieu-Daudé
@ 2020-02-28 10:07 ` Philippe Mathieu-Daudé
  2020-03-02 10:08 ` [PATCH v3 0/4] misc: Improve error reporting on Windows Markus Armbruster
  4 siblings, 0 replies; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-28 10:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Roth, Markus Armbruster,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau, Philippe Mathieu-Daudé

The string returned by g_win32_error_message() has to be
deallocated with g_free().

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 qga/channel-win32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index 99648c95b6..4f04868a76 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -302,8 +302,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
                            OPEN_EXISTING,
                            FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
     if (c->handle == INVALID_HANDLE_VALUE) {
-        g_critical("error opening path %s: %s", newpath,
-                   g_win32_error_message(GetLastError()));
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        g_critical("error opening path %s: %s", newpath, emsg);
         return false;
     }
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 3/4] qga: Improve error report by calling error_setg_win32()
  2020-02-28 10:07 ` [PATCH v3 3/4] qga: " Philippe Mathieu-Daudé
@ 2020-02-28 10:23   ` Marc-André Lureau
  0 siblings, 0 replies; 7+ messages in thread
From: Marc-André Lureau @ 2020-02-28 10:23 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Michael Roth, Paolo Bonzini, Tomáš Golembiovský,
	qemu-devel, Markus Armbruster

On Fri, Feb 28, 2020 at 11:07 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v3: Keep slog() in qmp_guest_shutdown() (Marc-André)
> ---
>  qga/channel-win32.c  | 3 ++-
>  qga/commands-win32.c | 8 +++++---
>  2 files changed, 7 insertions(+), 4 deletions(-)

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


>
> diff --git a/qga/channel-win32.c b/qga/channel-win32.c
> index c86f4388db..99648c95b6 100644
> --- a/qga/channel-win32.c
> +++ b/qga/channel-win32.c
> @@ -308,7 +308,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
>      }
>
>      if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
> -        g_critical("error setting timeout for com port: %lu",GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        g_critical("error setting timeout for com port: %s", emsg);
>          CloseHandle(c->handle);
>          return false;
>      }
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 2461fd19bf..9c744d6405 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -315,8 +315,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
>      }
>
>      if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
> -        slog("guest-shutdown failed: %lu", GetLastError());
> -        error_setg(errp, QERR_UNDEFINED_ERROR);
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        slog("guest-shutdown failed: %s", emsg);
> +        error_setg_win32(errp, GetLastError(), "guest-shutdown failed");
>      }
>  }
>
> @@ -1319,7 +1320,8 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
>      DWORD ret = 0;
>
>      if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
> -        slog("failed to suspend guest, %lu", GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        slog("failed to suspend guest: %s", emsg);
>          ret = -1;
>      }
>      g_free(mode);
> --
> 2.21.1
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/4] misc: Improve error reporting on Windows
  2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2020-02-28 10:07 ` [PATCH v3 4/4] qga: Fix a memory leak Philippe Mathieu-Daudé
@ 2020-03-02 10:08 ` Markus Armbruster
  4 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2020-03-02 10:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Michael Roth, Markus Armbruster, qemu-devel,
	Tomáš Golembiovský, Paolo Bonzini,
	Marc-André Lureau

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> Few patches to improve bug reports on Windows.
> (i.e. https://bugs.launchpad.net/qemu/+bug/1657841)

Queued, thanks!



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-02 10:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-28 10:07 [PATCH v3 0/4] misc: Improve error reporting on Windows Philippe Mathieu-Daudé
2020-02-28 10:07 ` [PATCH v3 1/4] chardev: Improve error report by calling error_setg_win32() Philippe Mathieu-Daudé
2020-02-28 10:07 ` [PATCH v3 2/4] util/osdep: " Philippe Mathieu-Daudé
2020-02-28 10:07 ` [PATCH v3 3/4] qga: " Philippe Mathieu-Daudé
2020-02-28 10:23   ` Marc-André Lureau
2020-02-28 10:07 ` [PATCH v3 4/4] qga: Fix a memory leak Philippe Mathieu-Daudé
2020-03-02 10:08 ` [PATCH v3 0/4] misc: Improve error reporting on Windows Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).