From patchwork Mon Aug 1 14:23:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 107768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E48EDB7090 for ; Tue, 2 Aug 2011 01:12:52 +1000 (EST) Received: from localhost ([::1]:47401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QntPk-0003Q7-5v for incoming@patchwork.ozlabs.org; Mon, 01 Aug 2011 10:24:16 -0400 Received: from eggs.gnu.org ([140.186.70.92]:40672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QntPG-000273-Fe for qemu-devel@nongnu.org; Mon, 01 Aug 2011 10:23:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QntPF-000564-Kw for qemu-devel@nongnu.org; Mon, 01 Aug 2011 10:23:46 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:41390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QntPF-00055z-IF for qemu-devel@nongnu.org; Mon, 01 Aug 2011 10:23:45 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p71Doxls014907 for ; Mon, 1 Aug 2011 09:50:59 -0400 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p71ENcp6142182 for ; Mon, 1 Aug 2011 10:23:39 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p71ANGoq018307 for ; Mon, 1 Aug 2011 07:23:16 -0300 Received: from titi.austin.rr.com (sig-9-76-195-114.mts.ibm.com [9.76.195.114]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p71AN0qL016760; Mon, 1 Aug 2011 07:23:15 -0300 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 1 Aug 2011 09:23:10 -0500 Message-Id: <1312208590-25502-13-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1312208590-25502-1-git-send-email-aliguori@us.ibm.com> References: <1312208590-25502-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.182.139 Cc: Amit Shah , Hans de Goede , Anthony Liguori Subject: [Qemu-devel] [PATCH 12/12] char: enforce the use of qemu_chr_guest_open() 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 Signed-off-by: Anthony Liguori --- qemu-char.c | 10 ++++++++++ qemu-char.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index fb7c937..5e62795 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -206,6 +206,8 @@ int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len) int ret; bool is_empty; + assert(s->fe_opened > 0); + is_empty = char_queue_get_empty(&s->fe_tx); ret = char_queue_write(&s->fe_tx, buf, len); @@ -228,6 +230,8 @@ int qemu_chr_fe_read(CharDriverState *s, uint8_t *buf, int len) bool is_full; int ret; + assert(s->fe_opened > 0); + is_full = (char_queue_get_avail(&s->be_tx) == 0); ret = char_queue_read(&s->be_tx, buf, len); @@ -249,6 +253,8 @@ void qemu_chr_fe_set_handlers(CharDriverState *s, IOEventHandler *chr_event, void *opaque) { + assert(s->fe_opened > 0); + if (!opaque && !chr_read && !chr_write && !chr_event) { /* chr driver being released. */ ++s->avail_connections; @@ -2822,6 +2828,8 @@ void qemu_chr_set_echo(struct CharDriverState *chr, bool echo) void qemu_chr_fe_open(struct CharDriverState *chr) { + chr->fe_opened++; + if (chr->chr_guest_open) { chr->chr_guest_open(chr); } @@ -2832,6 +2840,8 @@ void qemu_chr_fe_close(struct CharDriverState *chr) if (chr->chr_guest_close) { chr->chr_guest_close(chr); } + + chr->fe_opened--; } void qemu_chr_close(CharDriverState *chr) diff --git a/qemu-char.h b/qemu-char.h index 8b37fcf..b910c5e 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -88,6 +88,8 @@ struct CharDriverState { int opened; int avail_connections; + int fe_opened; + CharQueue fe_tx; CharQueue be_tx;