From patchwork Wed Oct 31 17:45:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 195973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D3E312C0081 for ; Thu, 1 Nov 2012 04:51:22 +1100 (EST) Received: from localhost ([::1]:34923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTcRk-0004si-TB for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 13:51:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTcRY-0004WD-4I for qemu-devel@nongnu.org; Wed, 31 Oct 2012 13:51:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTcRT-0000pj-Gn for qemu-devel@nongnu.org; Wed, 31 Oct 2012 13:51:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15974) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTcRT-0000pI-8s for qemu-devel@nongnu.org; Wed, 31 Oct 2012 13:51:03 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9VHiVmd031652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 31 Oct 2012 13:44:31 -0400 Received: from localhost (ovpn-113-84.phx2.redhat.com [10.3.113.84]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9VHiUkV031771; Wed, 31 Oct 2012 13:44:31 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2012 15:45:19 -0200 Message-Id: <1351705520-24589-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1351705520-24589-1-git-send-email-lcapitulino@redhat.com> References: <1351705520-24589-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 4/5] qemu-ga: win32: isolate virtio-serial specific code 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 This commit prepares ga_channel_new(), ga_channel_read() and ga_channel_open() for isa-serial support. Signed-off-by: Luiz Capitulino Reviewed-by: Michael Roth --- qga/channel-win32.c | 75 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/qga/channel-win32.c b/qga/channel-win32.c index 8e259c3..c173270 100644 --- a/qga/channel-win32.c +++ b/qga/channel-win32.c @@ -213,14 +213,20 @@ GIOStatus ga_channel_read(GAChannel *c, char *buf, size_t size, gsize *count) return G_IO_STATUS_ERROR; } - *count = to_read = MIN(size, rs->pending); - if (to_read) { - memcpy(buf, rs->buf + rs->cur, to_read); - rs->cur += to_read; - rs->pending -= to_read; - status = G_IO_STATUS_NORMAL; - } else { - status = G_IO_STATUS_AGAIN; + switch (c->method) { + case GA_CHANNEL_VIRTIO_SERIAL: + *count = to_read = MIN(size, rs->pending); + if (to_read) { + memcpy(buf, rs->buf + rs->cur, to_read); + rs->cur += to_read; + rs->pending -= to_read; + status = G_IO_STATUS_NORMAL; + } else { + status = G_IO_STATUS_AGAIN; + } + break; + default: + abort(); /* impossible */ } return status; @@ -285,23 +291,11 @@ GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size) return status; } -static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method, - const gchar *path) +static gboolean ga_channel_open(GAChannel *c, const gchar *path, int flags) { - if (!method == GA_CHANNEL_VIRTIO_SERIAL) { - g_critical("unsupported communication method"); - return false; - } - c->handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL); - if (c->handle == INVALID_HANDLE_VALUE) { - g_critical("error opening path"); - return false; - } - - return true; + OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | flags, NULL); + return (c->handle == INVALID_HANDLE_VALUE) ? false : true; } GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, @@ -310,27 +304,42 @@ GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, GAChannel *c = g_malloc0(sizeof(GAChannel)); SECURITY_ATTRIBUTES sec_attrs; - if (!ga_channel_open(c, method, path)) { - g_critical("error opening channel"); - g_free(c); - return NULL; + switch (method) { + case GA_CHANNEL_VIRTIO_SERIAL: + if (!ga_channel_open(c, path, FILE_FLAG_OVERLAPPED)) { + g_critical("error opening channel (path: %s)", path); + goto out_err; + } + + sec_attrs.nLength = sizeof(SECURITY_ATTRIBUTES); + sec_attrs.lpSecurityDescriptor = NULL; + sec_attrs.bInheritHandle = false; + c->rstate.ov.hEvent = CreateEvent(&sec_attrs, FALSE, FALSE, NULL); + if (!c->rstate.ov.hEvent) { + g_critical("can't create event"); + goto out_err; + } + + c->source = ga_channel_create_watch_ov(c); + break; + default: + g_critical("unsupported communication method"); + goto out_err; } c->cb = cb; c->user_data = opaque; c->method = method; - sec_attrs.nLength = sizeof(SECURITY_ATTRIBUTES); - sec_attrs.lpSecurityDescriptor = NULL; - sec_attrs.bInheritHandle = false; - c->rstate.buf_size = QGA_READ_COUNT_DEFAULT; c->rstate.buf = g_malloc(QGA_READ_COUNT_DEFAULT); - c->rstate.ov.hEvent = CreateEvent(&sec_attrs, FALSE, FALSE, NULL); - c->source = ga_channel_create_watch_ov(c); g_source_attach(c->source, NULL); return c; + +out_err: + g_free(c); + return NULL; } void ga_channel_free(GAChannel *c)