From patchwork Fri Apr 5 13:12:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 234127 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 76A492C00C2 for ; Sat, 6 Apr 2013 00:14:30 +1100 (EST) Received: from localhost ([::1]:42453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO6TM-00066u-Ld for incoming@patchwork.ozlabs.org; Fri, 05 Apr 2013 09:14:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO6RM-0004a5-Qx for qemu-devel@nongnu.org; Fri, 05 Apr 2013 09:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UO6RH-0001lR-L2 for qemu-devel@nongnu.org; Fri, 05 Apr 2013 09:12:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO6RH-0001lH-C8 for qemu-devel@nongnu.org; Fri, 05 Apr 2013 09:12:19 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r35DCIYu004175 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Apr 2013 09:12:18 -0400 Received: from localhost (ovpn-113-146.phx2.redhat.com [10.3.113.146]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r35DCIqI030920; Fri, 5 Apr 2013 09:12:18 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 5 Apr 2013 09:12:10 -0400 Message-Id: <1365167531-17553-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1365167531-17553-1-git-send-email-lcapitulino@redhat.com> References: <1365167531-17553-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PULL 3/4] hmp: human-monitor-command: stop using the Memory chardev driver 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 The Memory chardev driver was added because, as the Monitor's output buffer was static, we needed a way to accumulate the output of an HMP commmand when ran by human-monitor-command. However, the Monitor's output buffer is now dynamic, so it's possible for the human-monitor-command to use it instead of the Memory chardev driver. This commit does that change, but there are two important observations about it: 1. We need a way to signal to the Monitor that it shouldn't call chardev functions when flushing its output. This is done by adding a new flag to the Monitor object called skip_flush (which is set to true by qmp_human_monitor_command()) 2. The current code has buffered semantics: QMP clients will only see a command's output if it flushes its output with a new-line character. This commit changes this to unbuffered, which means that QMP clients will see a command's output whenever the command prints anything. I don't think this will matter in practice though, as I believe all HMP commands print the new-line character anyway. Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake Acked-by: Gerd Hoffmann --- monitor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 8712c53..b4bda77 100644 --- a/monitor.c +++ b/monitor.c @@ -188,6 +188,7 @@ struct Monitor { int reset_seen; int flags; int suspend_cnt; + bool skip_flush; QString *outbuf; ReadLineState *rs; MonitorControl *mc; @@ -273,6 +274,10 @@ void monitor_flush(Monitor *mon) size_t len; const char *buf; + if (mon->skip_flush) { + return; + } + buf = qstring_get_str(mon->outbuf); len = qstring_get_length(mon->outbuf); @@ -675,13 +680,10 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, { char *output = NULL; Monitor *old_mon, hmp; - CharDriverState mchar; memset(&hmp, 0, sizeof(hmp)); hmp.outbuf = qstring_new(); - - qemu_chr_init_mem(&mchar); - hmp.chr = &mchar; + hmp.skip_flush = true; old_mon = cur_mon; cur_mon = &hmp; @@ -699,17 +701,14 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, handle_user_command(&hmp, command_line); cur_mon = old_mon; - if (qemu_chr_mem_osize(hmp.chr) > 0) { - QString *str = qemu_chr_mem_to_qs(hmp.chr); - output = g_strdup(qstring_get_str(str)); - QDECREF(str); + if (qstring_get_length(hmp.outbuf) > 0) { + output = g_strdup(qstring_get_str(hmp.outbuf)); } else { output = g_strdup(""); } out: QDECREF(hmp.outbuf); - qemu_chr_close_mem(hmp.chr); return output; }