All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/2] Dump patches
@ 2018-03-21 14:37 Marc-André Lureau
  2018-03-21 14:37 ` [Qemu-devel] [PULL 1/2] dump.c: allow fd_write_vmcore to return errno on failure Marc-André Lureau
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Marc-André Lureau @ 2018-03-21 14:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Marc-André Lureau

The following changes since commit f1a63fcfcd92c88be8942b5ae71aef9749a4f135:

  Update version for v2.12.0-rc0 release (2018-03-20 19:04:22 +0000)

are available in the Git repository at:

  https://github.com/elmarco/qemu.git tags/dump-pull-request

for you to fetch changes up to 4b17bc933fc26f7a4a306a43597f4d97e3c2dc38:

  dump-guest-memory: more descriptive lookup_type failure (2018-03-21 15:02:00 +0100)

----------------------------------------------------------------
Pull request

----------------------------------------------------------------

Andrew Jones (1):
  dump-guest-memory: more descriptive lookup_type failure

Yasmin Beatriz (1):
  dump.c: allow fd_write_vmcore to return errno on failure

 scripts/dump-guest-memory.py |  7 ++++++-
 dump.c                       | 23 ++++++++++++++---------
 2 files changed, 20 insertions(+), 10 deletions(-)

-- 
2.16.2.521.g9aa15f885a

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

* [Qemu-devel] [PULL 1/2] dump.c: allow fd_write_vmcore to return errno on failure
  2018-03-21 14:37 [Qemu-devel] [PULL 0/2] Dump patches Marc-André Lureau
@ 2018-03-21 14:37 ` Marc-André Lureau
  2018-03-21 14:37 ` [Qemu-devel] [PULL 2/2] dump-guest-memory: more descriptive lookup_type failure Marc-André Lureau
  2018-03-22 14:01 ` [Qemu-devel] [PULL 0/2] Dump patches Peter Maydell
  2 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2018-03-21 14:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, Yasmin Beatriz, Jose Ricardo Ziviani,
	Daniel Henrique Barboza, Marc-André Lureau

From: Yasmin Beatriz <yasmins@linux.vnet.ibm.com>

fd_write_vmcore can fail to execute for a lot of reasons that can be
retrieved by errno, but it only returns -1. This makes difficult for
the caller to know what happened and only a generic error message is
propagated back to the user. This is an example using dump-guest-memory:

(qemu) dump-guest-memory /home/yasmin/mnt/test.dump
dump: failed to save memory

All callers of fd_write_vmcore of dump.c does error handling via
error_setg(), so at first it seems feasible to add the Error pointer as
an argument of fd_write_vmcore. This proved to be more complex than it
first looked. fd_write_vmcore is used by write_elf64_notes and
write_elf32_notes as a WriteCoreDumpFunction prototype. WriteCoreDumpFunction
is declared in include/qom/cpu.h and is used all around the code. This
leaves us with few alternatives:

- change the WriteCoreDumpFunction prototype to include an error pointer.
This would require to change all functions that implements this prototype
to also receive an Error pointer;

- change both write_elf64_notes and write_elf32_notes to no use the
WriteCoreDumpFunction. These functions use not only fd_write_vmcore
but also buf_write_note, so this would require to change buf_write_note
to handle an Error pointer. Considerable easier than the alternative
above, but it's still a lot of code just for the benefit of the callers
of fd_write_vmcore.

This patch presents an easier solution that benefits all fd_write_vmcore
callers:

- instead of returning -1 on error, return -errno. All existing callers
already checks for ret < 0 so there is no need to change the caller's
logic too much. This also allows the retrieval of the errno.

- all callers were updated to use error_setg_errno instead of just
errno_setg. Now that fd_write_vmcore can return an errno, let's update
all callers so they can benefit from a more detailed error message.

This is the same dump-guest-memory example with this patch applied:

(qemu) dump-guest-memory /home/yasmin/mnt/test.dump
dump: failed to save memory: No space left on device
(qemu)

This example illustrates an error of fd_write_vmcore when called
from write_data. All other callers will benefit from better
error messages as well.

Reported-by: yilzhang@redhat.com
Cc: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
Signed-off-by: Yasmin Beatriz <yasmins@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Message-Id: <20180212142506.28445-2-danielhb@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 dump.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/dump.c b/dump.c
index 6bdb0dbe23..669f715274 100644
--- a/dump.c
+++ b/dump.c
@@ -107,7 +107,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
 
     written_size = qemu_write_full(s->fd, buf, size);
     if (written_size != size) {
-        return -1;
+        return -errno;
     }
 
     return 0;
@@ -140,7 +140,7 @@ static void write_elf64_header(DumpState *s, Error **errp)
 
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write elf header");
+        error_setg_errno(errp, -ret, "dump: failed to write elf header");
     }
 }
 
@@ -171,7 +171,7 @@ static void write_elf32_header(DumpState *s, Error **errp)
 
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write elf header");
+        error_setg_errno(errp, -ret, "dump: failed to write elf header");
     }
 }
 
@@ -194,7 +194,8 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write program header table");
+        error_setg_errno(errp, -ret,
+                         "dump: failed to write program header table");
     }
 }
 
@@ -217,7 +218,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write program header table");
+        error_setg_errno(errp, -ret,
+                         "dump: failed to write program header table");
     }
 }
 
@@ -237,7 +239,8 @@ static void write_elf64_note(DumpState *s, Error **errp)
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write program header table");
+        error_setg_errno(errp, -ret,
+                         "dump: failed to write program header table");
     }
 }
 
@@ -302,7 +305,8 @@ static void write_elf32_note(DumpState *s, Error **errp)
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write program header table");
+        error_setg_errno(errp, -ret,
+                         "dump: failed to write program header table");
     }
 }
 
@@ -355,7 +359,8 @@ static void write_elf_section(DumpState *s, int type, Error **errp)
 
     ret = fd_write_vmcore(&shdr, shdr_size, s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to write section header table");
+        error_setg_errno(errp, -ret,
+                         "dump: failed to write section header table");
     }
 }
 
@@ -365,7 +370,7 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)
 
     ret = fd_write_vmcore(buf, length, s);
     if (ret < 0) {
-        error_setg(errp, "dump: failed to save memory");
+        error_setg_errno(errp, -ret, "dump: failed to save memory");
     } else {
         s->written_size += length;
     }
-- 
2.16.2.521.g9aa15f885a

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

* [Qemu-devel] [PULL 2/2] dump-guest-memory: more descriptive lookup_type failure
  2018-03-21 14:37 [Qemu-devel] [PULL 0/2] Dump patches Marc-André Lureau
  2018-03-21 14:37 ` [Qemu-devel] [PULL 1/2] dump.c: allow fd_write_vmcore to return errno on failure Marc-André Lureau
@ 2018-03-21 14:37 ` Marc-André Lureau
  2018-03-22 14:01 ` [Qemu-devel] [PULL 0/2] Dump patches Peter Maydell
  2 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2018-03-21 14:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Andrew Jones, Marc-André Lureau

From: Andrew Jones <drjones@redhat.com>

We've seen a few reports of

 (gdb) source /usr/share/qemu-kvm/dump-guest-memory.py
 Traceback (most recent call last):
   File "/usr/share/qemu-kvm/dump-guest-memory.py", line 19, in <module>
     UINTPTR_T = gdb.lookup_type("uintptr_t")
 gdb.error: No type named uintptr_t.

This occurs when symbols haven't been loaded first, i.e. neither a
QEMU binary was loaded nor a QEMU process was attached first. Let's
better inform the user of how to fix the issue themselves in order
to avoid more reports.

Acked-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Signed-off-by: Andrew Jones <drjones@redhat.com>
Message-Id: <20180314153820.18426-1-drjones@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Tested-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/dump-guest-memory.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py
index 51acfcd0c0..276eebf0c2 100644
--- a/scripts/dump-guest-memory.py
+++ b/scripts/dump-guest-memory.py
@@ -16,7 +16,12 @@ the COPYING file in the top-level directory.
 import ctypes
 import struct
 
-UINTPTR_T = gdb.lookup_type("uintptr_t")
+try:
+    UINTPTR_T = gdb.lookup_type("uintptr_t")
+except Exception as inst:
+    raise gdb.GdbError("Symbols must be loaded prior to sourcing dump-guest-memory.\n"
+                       "Symbols may be loaded by 'attach'ing a QEMU process id or by "
+                       "'load'ing a QEMU binary.")
 
 TARGET_PAGE_SIZE = 0x1000
 TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
-- 
2.16.2.521.g9aa15f885a

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

* Re: [Qemu-devel] [PULL 0/2] Dump patches
  2018-03-21 14:37 [Qemu-devel] [PULL 0/2] Dump patches Marc-André Lureau
  2018-03-21 14:37 ` [Qemu-devel] [PULL 1/2] dump.c: allow fd_write_vmcore to return errno on failure Marc-André Lureau
  2018-03-21 14:37 ` [Qemu-devel] [PULL 2/2] dump-guest-memory: more descriptive lookup_type failure Marc-André Lureau
@ 2018-03-22 14:01 ` Peter Maydell
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2018-03-22 14:01 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: QEMU Developers

On 21 March 2018 at 14:37, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
> The following changes since commit f1a63fcfcd92c88be8942b5ae71aef9749a4f135:
>
>   Update version for v2.12.0-rc0 release (2018-03-20 19:04:22 +0000)
>
> are available in the Git repository at:
>
>   https://github.com/elmarco/qemu.git tags/dump-pull-request
>
> for you to fetch changes up to 4b17bc933fc26f7a4a306a43597f4d97e3c2dc38:
>
>   dump-guest-memory: more descriptive lookup_type failure (2018-03-21 15:02:00 +0100)
>
> ----------------------------------------------------------------
> Pull request
>
> ----------------------------------------------------------------
>
> Andrew Jones (1):
>   dump-guest-memory: more descriptive lookup_type failure
>
> Yasmin Beatriz (1):
>   dump.c: allow fd_write_vmcore to return errno on failure
>
>  scripts/dump-guest-memory.py |  7 ++++++-
>  dump.c                       | 23 ++++++++++++++---------
>  2 files changed, 20 insertions(+), 10 deletions(-)
>
> --
> 2.16.2.521.g9aa15f885a

Applied, thanks.

-- PMM

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

* Re: [Qemu-devel] [PULL 0/2] Dump patches
  2018-01-02 14:06 Marc-André Lureau
@ 2018-01-08 21:38 ` Peter Maydell
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2018-01-08 21:38 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: QEMU Developers

On 2 January 2018 at 14:06, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
> The following changes since commit 281f327487c9c9b1599f93c589a408bbf4a651b8:
>
>   Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-2.12-pull-request' into staging (2017-12-22 00:11:36 +0000)
>
> are available in the Git repository at:
>
>   https://github.com/elmarco/qemu.git tags/dump-pull-request
>
> for you to fetch changes up to c3b1642b9b6b3ba4314d6be3be509d396372cfd5:
>
>   dump-guest-memory.py: fix "You can't do that without a process to debug" (2018-01-02 14:49:54 +0100)
>
> ----------------------------------------------------------------
>
> ----------------------------------------------------------------
>
> Marc-André Lureau (2):
>   dump: fix note_name_equal()
>   dump-guest-memory.py: fix "You can't do that without a process to
>     debug"
>
>  scripts/dump-guest-memory.py | 3 +--
>  dump.c                       | 7 +------
>  hw/misc/vmcoreinfo.c         | 3 +++
>  3 files changed, 5 insertions(+), 8 deletions(-)

Applied, thanks.

-- PMM

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

* [Qemu-devel] [PULL 0/2] Dump patches
@ 2018-01-02 14:06 Marc-André Lureau
  2018-01-08 21:38 ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Marc-André Lureau @ 2018-01-02 14:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Marc-André Lureau

The following changes since commit 281f327487c9c9b1599f93c589a408bbf4a651b8:

  Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-2.12-pull-request' into staging (2017-12-22 00:11:36 +0000)

are available in the Git repository at:

  https://github.com/elmarco/qemu.git tags/dump-pull-request

for you to fetch changes up to c3b1642b9b6b3ba4314d6be3be509d396372cfd5:

  dump-guest-memory.py: fix "You can't do that without a process to debug" (2018-01-02 14:49:54 +0100)

----------------------------------------------------------------

----------------------------------------------------------------

Marc-André Lureau (2):
  dump: fix note_name_equal()
  dump-guest-memory.py: fix "You can't do that without a process to
    debug"

 scripts/dump-guest-memory.py | 3 +--
 dump.c                       | 7 +------
 hw/misc/vmcoreinfo.c         | 3 +++
 3 files changed, 5 insertions(+), 8 deletions(-)

-- 
2.15.1.355.g36791d7216

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

end of thread, other threads:[~2018-03-22 14:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 14:37 [Qemu-devel] [PULL 0/2] Dump patches Marc-André Lureau
2018-03-21 14:37 ` [Qemu-devel] [PULL 1/2] dump.c: allow fd_write_vmcore to return errno on failure Marc-André Lureau
2018-03-21 14:37 ` [Qemu-devel] [PULL 2/2] dump-guest-memory: more descriptive lookup_type failure Marc-André Lureau
2018-03-22 14:01 ` [Qemu-devel] [PULL 0/2] Dump patches Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2018-01-02 14:06 Marc-André Lureau
2018-01-08 21:38 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.