From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJqZ9-000684-8d for qemu-devel@nongnu.org; Thu, 04 Oct 2012 14:54:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJqZ8-00024k-2a for qemu-devel@nongnu.org; Thu, 04 Oct 2012 14:54:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJqZ7-00023y-Q0 for qemu-devel@nongnu.org; Thu, 04 Oct 2012 14:54:34 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q94IsWpP029918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Oct 2012 14:54:33 -0400 Date: Thu, 4 Oct 2012 15:06:30 -0300 From: Luiz Capitulino Message-ID: <20121004150630.552307ed@doriath.home> In-Reply-To: <1349275025-5093-6-git-send-email-pbonzini@redhat.com> References: <1349275025-5093-1-git-send-email-pbonzini@redhat.com> <1349275025-5093-6-git-send-email-pbonzini@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 05/18] migration: avoid using error_is_set List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Wed, 3 Oct 2012 16:36:52 +0200 Paolo Bonzini wrote: > Signed-off-by: Paolo Bonzini The patch's description is a bit misleading. The real problem this fixes is that the migration code is using errp to detect "internal" errors, this means that it relies on errp being non-NULL. There's no problem using error_set(). Actually, I do prefer using it, because at least in theory we shouldn't assume the Error object to have this particular semantic. One more comment below. > --- > migration-tcp.c | 8 +++++--- > migration.c | 13 +++++++------ > 2 file modificati, 12 inserzioni(+), 9 rimozioni(-) > > diff --git a/migration-tcp.c b/migration-tcp.c > index a15c2b8..78337a3 100644 > --- a/migration-tcp.c > +++ b/migration-tcp.c > @@ -71,14 +71,16 @@ static void tcp_wait_for_connect(int fd, void *opaque) > int tcp_start_outgoing_migration(MigrationState *s, const char *host_port, > Error **errp) > { > + Error *local_err = NULL; > + > s->get_error = socket_errno; > s->write = socket_write; > s->close = tcp_close; > > - s->fd = inet_nonblocking_connect(host_port, tcp_wait_for_connect, s, > - errp); > - if (error_is_set(errp)) { > + s->fd = inet_nonblocking_connect(host_port, tcp_wait_for_connect, s, &local_err); > + if (local_err != NULL) { > migrate_fd_error(s); > + error_propagate(errp, local_err); > return -1; > } > > diff --git a/migration.c b/migration.c > index 22a05c4..8a04174 100644 > --- a/migration.c > +++ b/migration.c > @@ -481,6 +481,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, > bool has_inc, bool inc, bool has_detach, bool detach, > Error **errp) > { > + Error *local_err = NULL; > MigrationState *s = migrate_get_current(); > MigrationParams params; > const char *p; > @@ -506,7 +507,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, > s = migrate_init(¶ms); > > if (strstart(uri, "tcp:", &p)) { > - ret = tcp_start_outgoing_migration(s, p, errp); > + ret = tcp_start_outgoing_migration(s, p, &local_err); > #if !defined(WIN32) > } else if (strstart(uri, "exec:", &p)) { > ret = exec_start_outgoing_migration(s, p); > @@ -520,11 +521,11 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, > return; > } > > - if (ret < 0) { > - if (!error_is_set(errp)) { > - DPRINTF("migration failed: %s\n", strerror(-ret)); > - /* FIXME: we should return meaningful errors */ > - error_set(errp, QERR_UNDEFINED_ERROR); > + if (ret < 0 || local_err) { > + if (!local_err) { > + error_set_errno(errp, -ret, QERR_UNDEFINED_ERROR); Two problems here. First, ret usually is not -errno. If we really want to use it here (I think this is great improvement) than we have to fix the functions called by qmp_migrate() first. The other problem is just this will produce a weird error message, it's better to do s/QERR_UNDEFINED_ERROR/"migration has failed". > + } else { > + error_propagate(errp, local_err); > } > return; > }