qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return


From: Murilo Opsfelder Araujo
Subject: Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure
Date: Mon, 12 Feb 2018 17:19:38 -0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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 <address@hidden>
>>>
>>> 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]