qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-sockets: Fix assertion failure
Date: Tue, 19 Mar 2013 16:34:51 -0400	[thread overview]
Message-ID: <20130319163451.205bc2cd@doriath> (raw)
In-Reply-To: <513756D5.1020506@redhat.com>

On Wed, 06 Mar 2013 15:46:45 +0100
Laszlo Ersek <lersek@redhat.com> wrote:

> On 03/06/13 12:11, Kevin Wolf wrote:
> > Am 06.03.2013 um 12:04 hat Paolo Bonzini geschrieben:
> >> Il 06/03/2013 11:48, Kevin Wolf ha scritto:
> >>> inet_connect_opts() tries all possible addrinfos returned by
> >>> getaddrinfo(). If one fails with an error, the next one is tried. In
> >>> this case, the Error should be discarded because the whole operation is
> >>> successful if another addrinfo from the list succeeds; and if it
> >>> doesn't, setting an already set Error will trigger an assertion failure.
> >>>
> >>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> >>> ---
> >>>  util/qemu-sockets.c | 8 ++++++++
> >>>  1 file changed, 8 insertions(+)
> >>>
> >>> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> >>> index 1350ccc..32e609a 100644
> >>> --- a/util/qemu-sockets.c
> >>> +++ b/util/qemu-sockets.c
> >>> @@ -373,6 +373,14 @@ int inet_connect_opts(QemuOpts *opts, Error **errp,
> >>>      }
> >>>  
> >>>      for (e = res; e != NULL; e = e->ai_next) {
> >>> +
> >>> +        /* Overwriting errors isn't allowed, so clear any error that may have
> >>> +         * occured in the previous iteration */
> >>> +        if (error_is_set(errp)) {
> >>> +            error_free(*errp);
> >>> +            *errp = NULL;
> >>> +        }
> >>> +
> >>>          if (connect_state != NULL) {
> >>>              connect_state->current_addr = e;
> >>>          }
> >>>
> >>
> >> Should we also do nothing if errp is not NULL on entry?
> > 
> > We could assert(!error_is_set(errp)) if we wanted. As soon as you've got
> > an Error, you must return instead of calling more functions with the
> > same error pointer.
> 
> I think Luiz would suggest (*) to receive any error into a
> NULL-initialized local_err pointer; do the logic above on local_err, and
> just before returning, error_propagate() it to errp.

Yes, I'd suggest that but it turns out that inet_connect_addr() error
reporting was and still is confusing, which causes callers to use it
incorrectly.

This patch (which has been applied by Anthony) solves the problem at
hand but it also introduces a new issue: errors from inet_connect_addr()
are only reported if they happen in the last loop interaction. Note that
a few other errors other than 'couldn't connect' can happen.

Laszlo's comment seemed to have triggered a discussion around Error **,
but this really has very little to do with it: the real problem is that
inet_connect_addr() is too confusing.

inet_connect_addr() has two users: inet_connect_opts() and wait_for_connect(),
with this patch both of them are now ignoring errors from inet_connect_addr().

Suggested solution: refactor inet_connect_addr() to return an errno value.
Callers use error_set() when they want to report an error upward.

  parent reply	other threads:[~2013-03-19 20:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06 10:48 [Qemu-devel] [PATCH] qemu-sockets: Fix assertion failure Kevin Wolf
2013-03-06 11:04 ` Paolo Bonzini
2013-03-06 11:11   ` Kevin Wolf
2013-03-06 14:46     ` Laszlo Ersek
2013-03-06 15:04       ` Paolo Bonzini
2013-03-06 15:19         ` Kevin Wolf
2013-03-06 15:38           ` Laszlo Ersek
2013-03-06 15:47             ` Kevin Wolf
2013-03-06 16:04               ` Laszlo Ersek
2013-03-06 15:59           ` Markus Armbruster
2013-03-06 16:43             ` Paolo Bonzini
2013-03-14 14:57             ` [Qemu-devel] [RFC PATCH] qemu-socket: Use local error variable Kevin Wolf
2013-03-14 15:52               ` Laszlo Ersek
2013-03-15  8:37                 ` Kevin Wolf
2013-03-15 16:55                   ` Laszlo Ersek
2013-03-15 17:55                     ` Kevin Wolf
2013-03-15 18:39                       ` Laszlo Ersek
2013-03-19 20:34       ` Luiz Capitulino [this message]
2013-03-20  8:39         ` [Qemu-devel] [PATCH] qemu-sockets: Fix assertion failure Kevin Wolf
2013-03-20 12:57           ` Luiz Capitulino
2013-03-20 13:37             ` Kevin Wolf
2013-03-20 13:52               ` Luiz Capitulino
2013-03-06 15:05     ` Markus Armbruster
2013-03-06 15:05 ` [Qemu-devel] Error ** parameter conventions (was: [PATCH] qemu-sockets: Fix assertion failure) Markus Armbruster

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=20130319163451.205bc2cd@doriath \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=lersek@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 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).