From patchwork Thu Sep 1 11:46:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 112898 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 BE44BB6F75 for ; Thu, 1 Sep 2011 22:02:43 +1000 (EST) Received: from localhost ([::1]:35057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz5yf-00085d-Ih for incoming@patchwork.ozlabs.org; Thu, 01 Sep 2011 08:02:37 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz5yN-00073y-Sf for qemu-devel@nongnu.org; Thu, 01 Sep 2011 08:02:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qz5jY-0003iC-5q for qemu-devel@nongnu.org; Thu, 01 Sep 2011 07:47:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qz5jX-0003gG-QX for qemu-devel@nongnu.org; Thu, 01 Sep 2011 07:47:00 -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 p81Bkwvt032480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Sep 2011 07:46:58 -0400 Received: from t500wlan.home.berrange.com.com (vpn1-7-126.ams2.redhat.com [10.36.7.126]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p81Bkvt0025020; Thu, 1 Sep 2011 07:46:57 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 1 Sep 2011 12:46:44 +0100 Message-Id: <1314877604-2720-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Gleb Natapov Subject: [Qemu-devel] [PATCH] Preserve current monitor CPU when issuing HMP passthrough commands 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: "Daniel P. Berrange" Several info commands rely on the 'mon_cpu' field in the Monitor struct. This field can be updated using the 'cpu NN' command. The processing for HMP passthrough commands, however, does not use the global 'Monitor *' instance, instead creating a brand new instance on the stack for HMP command executed. This breaks anything setting/getting the current monitor CPU $ ./x86_64-softmmu/qemu-system-x86_64 -cdrom ~/boot.iso -qmp stdio -smp 4 {"QMP": {"version": {"qemu": {"micro": 50, "minor": 15, "major": 0}, "package": ""}, "capabilities": []}} {"execute":"qmp_capabilities"} {"return": {}} {"execute":"human-monitor-command","arguments":{"command-line":"info cpus"}} {"return": "* CPU #0: pc=0x000000000010017c (halted) thread_id=2570 \r\n CPU #1: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n CPU #2: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n CPU #3: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n"} {"execute":"human-monitor-command","arguments":{"command-line":"cpu 2"}} {"return": {}} {"execute":"human-monitor-command","arguments":{"command-line":"info cpus"}} {"return": "* CPU #0: pc=0x000000000010017c (halted) thread_id=2570 \r\n CPU #1: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n CPU #2: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n CPU #3: pc=0x00000000000ff0a2 (halted) thread_id=2570 \r\n"} In that example, the '*' should have moved from CPU #0, to CPU #2 but it did not. The simple fix is to just copy the existing 'mon_cpu' field into the new temporary Monitor instance, before the HMP command is run, and copy the updated value back to the global instance afterwards. * monitor.c: Track 'mon_cpu' when doing HMP passthrough Signed-off-by: Daniel P. Berrange --- monitor.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index 421a65c..f99659d 100644 --- a/monitor.c +++ b/monitor.c @@ -513,6 +513,7 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params, memset(&hmp, 0, sizeof(hmp)); qemu_chr_init_mem(&mchar); hmp.chr = &mchar; + hmp.mon_cpu = cur_mon->mon_cpu; old_mon = cur_mon; cur_mon = &hmp; @@ -521,6 +522,7 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params, ret = mon_set_cpu(qdict_get_int(params, "cpu-index")); if (ret < 0) { cur_mon = old_mon; + cur_mon->mon_cpu = hmp.mon_cpu; qerror_report(QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); goto out; } @@ -528,6 +530,7 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params, handle_user_command(&hmp, qdict_get_str(params, "command-line")); cur_mon = old_mon; + cur_mon->mon_cpu = hmp.mon_cpu; if (qemu_chr_mem_osize(hmp.chr) > 0) { *ret_data = QOBJECT(qemu_chr_mem_to_qs(hmp.chr));