From patchwork Mon Oct 6 17:59:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 396883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B073B14007B for ; Tue, 7 Oct 2014 05:01:02 +1100 (EST) Received: from localhost ([::1]:53480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbCai-0007jT-RC for incoming@patchwork.ozlabs.org; Mon, 06 Oct 2014 14:01:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbCZn-0006cL-QF for qemu-devel@nongnu.org; Mon, 06 Oct 2014 14:00:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbCZf-0002jx-AN for qemu-devel@nongnu.org; Mon, 06 Oct 2014 14:00:03 -0400 Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:44692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbCZf-0002j1-0L for qemu-devel@nongnu.org; Mon, 06 Oct 2014 13:59:55 -0400 Received: by mail-oi0-f46.google.com with SMTP id h136so3958092oig.5 for ; Mon, 06 Oct 2014 10:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=kGQfzim3MoPMOrROK6ZEWFu591PSkpGssemKQiSB3tk=; b=wEoIuVXksAVMEXXHLVKxwvnIhcCUsVkyEXfSw9OIuUN1NzjRbXn00I3cD3miHG278R tuPqt0X3wohuwFw11FcE2YBn4hbptev1yoMX7AEvQIY8+1eJdIVcKYvL6MshLPXcuvKQ jx3Mr5N7Hc1o/05TycrEUxD8VLgcZwJmnbr8xy9lPrtkv39dCgZkiHhtB+kG+UjcxUBA iqMuwgkUOQydFEOP2dD7JOkToYoyWrdWTTtROQIu2BN+W3qmLDbpTIOmcE0XgYQxAot7 yQn9Hcqg5VRvTFufzSF4nfyV0jDgpwBCRiZanwqPRTuvG/ju7Jy2xCoULCdw03tQXjaz MkpA== X-Received: by 10.182.47.232 with SMTP id g8mr5049420obn.85.1412618394325; Mon, 06 Oct 2014 10:59:54 -0700 (PDT) Received: from t430.minyard.home (pool-173-57-152-84.dllstx.fios.verizon.net. [173.57.152.84]) by mx.google.com with ESMTPSA id cx4sm10571182obd.3.2014.10.06.10.59.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Oct 2014 10:59:53 -0700 (PDT) Received: from t430.minyard.home (t430.minyard.home [127.0.0.1]) by t430.minyard.home (8.14.7/8.14.7) with ESMTP id s96HxgSV015927; Mon, 6 Oct 2014 12:59:52 -0500 Received: (from cminyard@localhost) by t430.minyard.home (8.14.7/8.14.7/Submit) id s96HxVUg015916; Mon, 6 Oct 2014 12:59:31 -0500 From: minyard@acm.org To: qemu-devel@nongnu.org Date: Mon, 6 Oct 2014 12:59:22 -0500 Message-Id: <1412618363-14968-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1412618363-14968-1-git-send-email-minyard@acm.org> References: <1412618363-14968-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22e Cc: Corey Minyard Subject: [Qemu-devel] [PATCH 1/2] qemu-char: Fix reconnect socket error reporting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Corey Minyard If reconnect was set, errors wouldn't always be reported. Fix that and also only report a connect error once until a connection has been made. The primary purpose of this is to tell the user that a connection failed so they can know they need to figure out what went wrong. So we don't want to spew too much out here, just enough so they know. Signed-off-by: Corey Minyard --- qemu-char.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 62af0ef..fb895c7 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2509,6 +2509,7 @@ typedef struct { guint reconnect_timer; int64_t reconnect_time; + bool connect_err_reported; } TCPCharDriver; static gboolean socket_reconnect_timeout(gpointer opaque); @@ -2521,6 +2522,17 @@ static void qemu_chr_socket_restart_timer(CharDriverState *chr) socket_reconnect_timeout, chr); } +static void check_report_connect_error(CharDriverState *chr, const char *str) +{ + TCPCharDriver *s = chr->opaque; + + if (!s->connect_err_reported) { + error_report("%s char device %s\n", str, chr->label); + s->connect_err_reported = 1; + } + qemu_chr_socket_restart_timer(chr); +} + static gboolean tcp_chr_accept(GIOChannel *chan, GIOCondition cond, void *opaque); #ifndef _WIN32 @@ -3045,12 +3057,14 @@ static void qemu_chr_finish_socket_connection(CharDriverState *chr, int fd) static void qemu_chr_socket_connected(int fd, void *opaque) { CharDriverState *chr = opaque; + TCPCharDriver *s = chr->opaque; if (fd < 0) { - qemu_chr_socket_restart_timer(chr); + check_report_connect_error(chr, "Unable to connect to"); return; } + s->connect_err_reported = 0; qemu_chr_finish_socket_connection(chr, fd); } @@ -4066,11 +4080,19 @@ static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel, #endif /* WIN32 */ +static void socket_try_connect(CharDriverState *chr) +{ + Error *err = NULL; + + if (!qemu_chr_open_socket_fd(chr, &err)) { + check_report_connect_error(chr, "Unable to start connection to"); + } +} + static gboolean socket_reconnect_timeout(gpointer opaque) { CharDriverState *chr = opaque; TCPCharDriver *s = chr->opaque; - Error *err; s->reconnect_timer = 0; @@ -4078,10 +4100,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque) return false; } - if (!qemu_chr_open_socket_fd(chr, &err)) { - error_report("Unable to connect to char device %s\n", chr->label); - qemu_chr_socket_restart_timer(chr); - } + socket_try_connect(chr); return false; } @@ -4133,15 +4152,13 @@ static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock, s->reconnect_time = reconnect; } - if (!qemu_chr_open_socket_fd(chr, errp)) { - if (s->reconnect_time) { - qemu_chr_socket_restart_timer(chr); - } else { - g_free(s); - g_free(chr->filename); - g_free(chr); - return NULL; - } + if (s->reconnect_time) { + socket_try_connect(chr); + } else if (!qemu_chr_open_socket_fd(chr, errp)) { + g_free(s); + g_free(chr->filename); + g_free(chr); + return NULL; } if (is_listen && is_waitconnect) {