* [Qemu-devel] [PATCH v3 0/1] dump.c: allow fd_write_vmcore to return errno on failure @ 2018-02-12 14:25 Daniel Henrique Barboza 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza 2018-03-21 13:29 ` [Qemu-devel] [PATCH v3 0/1] " Daniel Henrique Barboza 0 siblings, 2 replies; 11+ messages in thread From: Daniel Henrique Barboza @ 2018-02-12 14:25 UTC (permalink / raw) To: qemu-devel; +Cc: marcandre.lureau, eblake, Daniel Henrique Barboza v3: - added set_errg_errno() to all callers of fd_write_vmcore - changed patch subject to reflect what it is addressing now - link to previous version: http://lists.gnu.org/archive/html/qemu-devel/2018-02/msg02787.html Yasmin Beatriz (1): dump.c: allow fd_write_vmcore to return errno on failure dump.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 2.14.3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:25 [Qemu-devel] [PATCH v3 0/1] dump.c: allow fd_write_vmcore to return errno on failure Daniel Henrique Barboza @ 2018-02-12 14:25 ` Daniel Henrique Barboza 2018-02-12 14:31 ` Marc-Andre Lureau ` (2 more replies) 2018-03-21 13:29 ` [Qemu-devel] [PATCH v3 0/1] " Daniel Henrique Barboza 1 sibling, 3 replies; 11+ messages in thread From: Daniel Henrique Barboza @ 2018-02-12 14:25 UTC (permalink / raw) To: qemu-devel Cc: marcandre.lureau, eblake, Yasmin Beatriz, Jose Ricardo Ziviani, Daniel Henrique Barboza 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> --- dump.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dump.c b/dump.c index 7b13baa413..171ff8a3b8 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.14.3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza @ 2018-02-12 14:31 ` Marc-Andre Lureau 2018-02-12 14:46 ` Murilo Opsfelder Araujo 2018-02-12 17:47 ` Eric Blake 2 siblings, 0 replies; 11+ messages in thread From: Marc-Andre Lureau @ 2018-02-12 14:31 UTC (permalink / raw) To: Daniel Henrique Barboza Cc: qemu-devel, marcandre, Blake, Eric, Yasmin Beatriz, Jose Ricardo Ziviani Hi On Mon, Feb 12, 2018 at 3:25 PM, Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> wrote: > 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> lgtm, Reviewed-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 7b13baa413..171ff8a3b8 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.14.3 > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza 2018-02-12 14:31 ` Marc-Andre Lureau @ 2018-02-12 14:46 ` Murilo Opsfelder Araujo 2018-02-12 15:49 ` Daniel Henrique Barboza 2018-02-12 17:31 ` Eric Blake 2018-02-12 17:47 ` Eric Blake 2 siblings, 2 replies; 11+ messages in thread From: Murilo Opsfelder Araujo @ 2018-02-12 14:46 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: marcandre.lureau, Yasmin Beatriz, Jose Ricardo Ziviani On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: > 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> > --- > dump.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/dump.c b/dump.c > index 7b13baa413..171ff8a3b8 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"); Do we need -ret passed to error_setg_errno()? fd_write_vmcore() returns negative errno in case of error. Cheers Murilo ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:46 ` Murilo Opsfelder Araujo @ 2018-02-12 15:49 ` Daniel Henrique Barboza 2018-02-12 17:31 ` Eric Blake 1 sibling, 0 replies; 11+ messages in thread From: Daniel Henrique Barboza @ 2018-02-12 15:49 UTC (permalink / raw) To: Murilo Opsfelder Araujo, qemu-devel Cc: marcandre.lureau, Yasmin Beatriz, Jose Ricardo Ziviani On 02/12/2018 12:46 PM, Murilo Opsfelder Araujo wrote: > On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: >> 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> >> --- >> dump.c | 23 ++++++++++++++--------- >> 1 file changed, 14 insertions(+), 9 deletions(-) >> >> diff --git a/dump.c b/dump.c >> index 7b13baa413..171ff8a3b8 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"); > Do we need -ret passed to error_setg_errno()? fd_write_vmcore() returns > negative errno in case of error. I am passing -ret here to provide a positive errno value to error_setg_errno. I am not sure if os_error can be negative and didn't want to risk strerror() breaking. Daniel > > Cheers > Murilo ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:46 ` Murilo Opsfelder Araujo 2018-02-12 15:49 ` Daniel Henrique Barboza @ 2018-02-12 17:31 ` Eric Blake 2018-02-12 19:19 ` Murilo Opsfelder Araujo 1 sibling, 1 reply; 11+ messages in thread From: Eric Blake @ 2018-02-12 17:31 UTC (permalink / raw) To: Murilo Opsfelder Araujo, Daniel Henrique Barboza, qemu-devel Cc: marcandre.lureau, Jose Ricardo Ziviani, Yasmin Beatriz On 02/12/2018 08:46 AM, Murilo Opsfelder Araujo wrote: > On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: >> 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: >> >> +++ 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"); > > Do we need -ret passed to error_setg_errno()? fd_write_vmcore() returns > negative errno in case of error. Yes, this usage is correct. error_setg_errno() takes a positive errno value (using strerror, which only decodes positive values into useful strings); but we typically return negative errno values (as was correctly done in fd_write_vmcore), so the extra layer of negation here is needed. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 17:31 ` Eric Blake @ 2018-02-12 19:19 ` Murilo Opsfelder Araujo 0 siblings, 0 replies; 11+ messages in thread From: Murilo Opsfelder Araujo @ 2018-02-12 19:19 UTC (permalink / raw) To: Eric Blake, Daniel Henrique Barboza, qemu-devel Cc: marcandre.lureau, Jose Ricardo Ziviani, Yasmin Beatriz On 02/12/2018 03:31 PM, Eric Blake wrote: > On 02/12/2018 08:46 AM, Murilo Opsfelder Araujo wrote: >> On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: >>> 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: >>> > >>> +++ 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"); >> >> Do we need -ret passed to error_setg_errno()? fd_write_vmcore() returns >> negative errno in case of error. > > Yes, this usage is correct. error_setg_errno() takes a positive errno > value (using strerror, which only decodes positive values into useful > strings); but we typically return negative errno values (as was > correctly done in fd_write_vmcore), so the extra layer of negation here > is needed. > For some reason I assumed "non-zero" in the error_setg_errno() description as negative. Thanks Daniel and Eric. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza 2018-02-12 14:31 ` Marc-Andre Lureau 2018-02-12 14:46 ` Murilo Opsfelder Araujo @ 2018-02-12 17:47 ` Eric Blake 2 siblings, 0 replies; 11+ messages in thread From: Eric Blake @ 2018-02-12 17:47 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: marcandre.lureau, Yasmin Beatriz, Jose Ricardo Ziviani On 02/12/2018 08:25 AM, Daniel Henrique Barboza wrote: > 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 > ... > 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> > --- > dump.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > Reviewed-by: Eric Blake <eblake@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-02-12 14:25 [Qemu-devel] [PATCH v3 0/1] dump.c: allow fd_write_vmcore to return errno on failure Daniel Henrique Barboza 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza @ 2018-03-21 13:29 ` Daniel Henrique Barboza 2018-03-21 13:56 ` [Qemu-devel] [PATCH v3 for-2.12? " Eric Blake 1 sibling, 1 reply; 11+ messages in thread From: Daniel Henrique Barboza @ 2018-03-21 13:29 UTC (permalink / raw) To: qemu-devel; +Cc: marcandre.lureau, Laurent Vivier, Eric Blake Ping On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: > v3: > - added set_errg_errno() to all callers of fd_write_vmcore > - changed patch subject to reflect what it is addressing now > - link to previous version: > http://lists.gnu.org/archive/html/qemu-devel/2018-02/msg02787.html > > > Yasmin Beatriz (1): > dump.c: allow fd_write_vmcore to return errno on failure > > dump.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 for-2.12? 0/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-03-21 13:29 ` [Qemu-devel] [PATCH v3 0/1] " Daniel Henrique Barboza @ 2018-03-21 13:56 ` Eric Blake 2018-03-21 14:20 ` Marc-André Lureau 0 siblings, 1 reply; 11+ messages in thread From: Eric Blake @ 2018-03-21 13:56 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: marcandre.lureau, Laurent Vivier, Paolo Bonzini On 03/21/2018 08:29 AM, Daniel Henrique Barboza wrote: > Ping > > On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: >> v3: >> - added set_errg_errno() to all callers of fd_write_vmcore >> - changed patch subject to reflect what it is addressing now >> - link to previous version: >> http://lists.gnu.org/archive/html/qemu-devel/2018-02/msg02787.html >> >> >> Yasmin Beatriz (1): >> dump.c: allow fd_write_vmcore to return errno on failure >> >> dump.c | 23 ++++++++++++++--------- >> 1 file changed, 14 insertions(+), 9 deletions(-) >> This seems like an appropriate bug-fix patch for inclusion in 2.12. Marc-André, are you planning a pull request, or should we bundle this through another miscellaneous tree? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v3 for-2.12? 0/1] dump.c: allow fd_write_vmcore to return errno on failure 2018-03-21 13:56 ` [Qemu-devel] [PATCH v3 for-2.12? " Eric Blake @ 2018-03-21 14:20 ` Marc-André Lureau 0 siblings, 0 replies; 11+ messages in thread From: Marc-André Lureau @ 2018-03-21 14:20 UTC (permalink / raw) To: Eric Blake Cc: Daniel Henrique Barboza, qemu-devel, Laurent Vivier, Paolo Bonzini Hi On Wed, Mar 21, 2018 at 2:56 PM, Eric Blake <eblake@redhat.com> wrote: > On 03/21/2018 08:29 AM, Daniel Henrique Barboza wrote: >> >> Ping >> >> On 02/12/2018 12:25 PM, Daniel Henrique Barboza wrote: >>> >>> v3: >>> - added set_errg_errno() to all callers of fd_write_vmcore >>> - changed patch subject to reflect what it is addressing now >>> - link to previous version: >>> http://lists.gnu.org/archive/html/qemu-devel/2018-02/msg02787.html >>> >>> >>> Yasmin Beatriz (1): >>> dump.c: allow fd_write_vmcore to return errno on failure >>> >>> dump.c | 23 ++++++++++++++--------- >>> 1 file changed, 14 insertions(+), 9 deletions(-) >>> > > This seems like an appropriate bug-fix patch for inclusion in 2.12. > Marc-André, are you planning a pull request, or should we bundle this > through another miscellaneous tree? Ok, I'll prepare a pull request. Thanks ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-03-21 14:20 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-02-12 14:25 [Qemu-devel] [PATCH v3 0/1] dump.c: allow fd_write_vmcore to return errno on failure Daniel Henrique Barboza 2018-02-12 14:25 ` [Qemu-devel] [PATCH v3 1/1] " Daniel Henrique Barboza 2018-02-12 14:31 ` Marc-Andre Lureau 2018-02-12 14:46 ` Murilo Opsfelder Araujo 2018-02-12 15:49 ` Daniel Henrique Barboza 2018-02-12 17:31 ` Eric Blake 2018-02-12 19:19 ` Murilo Opsfelder Araujo 2018-02-12 17:47 ` Eric Blake 2018-03-21 13:29 ` [Qemu-devel] [PATCH v3 0/1] " Daniel Henrique Barboza 2018-03-21 13:56 ` [Qemu-devel] [PATCH v3 for-2.12? " Eric Blake 2018-03-21 14:20 ` Marc-André Lureau
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.