All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Murilo Opsfelder Araujo <muriloo@linux.vnet.ibm.com>,
	Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com,
	Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com>,
	Yasmin Beatriz <yasmins@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/1] dump.c: allow fd_write_vmcore to return errno on failure
Date: Mon, 12 Feb 2018 11:31:35 -0600	[thread overview]
Message-ID: <b4cafa8f-efac-00e1-683a-304a91c695ca@redhat.com> (raw)
In-Reply-To: <98934c2f-2210-83d7-d629-157e5a7cee8e@linux.vnet.ibm.com>

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

  parent reply	other threads:[~2018-02-12 17:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4cafa8f-efac-00e1-683a-304a91c695ca@redhat.com \
    --to=eblake@redhat.com \
    --cc=danielhb@linux.vnet.ibm.com \
    --cc=joserz@linux.vnet.ibm.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=muriloo@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yasmins@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.