From patchwork Mon Oct 10 09:23:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 680330 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 3sswXm35B4z9s3s for ; Mon, 10 Oct 2016 20:57:44 +1100 (AEDT) Received: from localhost ([::1]:48519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btXL3-0005Gx-7I for incoming@patchwork.ozlabs.org; Mon, 10 Oct 2016 05:57:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWox-000319-BT for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWou-0003rI-Mn for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWou-0003qz-DT for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:24:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 020B1C04B935 for ; Mon, 10 Oct 2016 09:24:28 +0000 (UTC) Received: from localhost (ovpn-116-23.phx2.redhat.com [10.3.116.23]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9A9OPnT010461; Mon, 10 Oct 2016 05:24:27 -0400 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 10 Oct 2016 13:23:00 +0400 Message-Id: <20161010092301.14974-24-marcandre.lureau@redhat.com> In-Reply-To: <20161010092301.14974-1-marcandre.lureau@redhat.com> References: <20161010092301.14974-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 10 Oct 2016 09:24:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 23/24] console: make screendump async X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make screendump async to provide correct screendumps. HMP doesn't have async support, so it has to remain sync to avoid potential races. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1230527 Signed-off-by: Marc-André Lureau --- hmp.c | 2 +- ui/console.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++- include/ui/console.h | 1 + qapi-schema.json | 11 ++++++++- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/hmp.c b/hmp.c index 336e7bf..b161453 100644 --- a/hmp.c +++ b/hmp.c @@ -1809,7 +1809,7 @@ void hmp_screendump(Monitor *mon, const QDict *qdict) const char *filename = qdict_get_str(qdict, "filename"); Error *err = NULL; - qmp_screendump(filename, &err); + hmp_screendump_sync(filename, &err); hmp_handle_error(mon, &err); } diff --git a/ui/console.c b/ui/console.c index 7ca5d19..85f099c 100644 --- a/ui/console.c +++ b/ui/console.c @@ -114,6 +114,12 @@ typedef enum { TEXT_CONSOLE_FIXED_SIZE } console_type_t; +struct qmp_screendump { + gchar *filename; + QmpReturn *ret; + QLIST_ENTRY(qmp_screendump) link; +}; + struct QemuConsole { Object parent; @@ -162,6 +168,8 @@ struct QemuConsole { QEMUFIFO out_fifo; uint8_t out_fifo_buf[16]; QEMUTimer *kbd_timer; + + QLIST_HEAD(, qmp_screendump) qmp_screendumps; }; struct DisplayState { @@ -187,6 +195,8 @@ static void dpy_refresh(DisplayState *s); static DisplayState *get_alloc_displaystate(void); static void text_console_update_cursor_timer(void); static void text_console_update_cursor(void *opaque); +static void ppm_save(const char *filename, DisplaySurface *ds, + Error **errp); static void gui_update(void *opaque) { @@ -253,8 +263,39 @@ static void gui_setup_refresh(DisplayState *ds) ds->have_text = have_text; } +static void qmp_screendump_finish(QemuConsole *con, const char *filename, + QmpReturn *ret) +{ + Error *err = NULL; + DisplaySurface *surface; + + if (qmp_return_is_cancelled(ret)) { + return; + } + + surface = qemu_console_surface(con); + + /* FIXME: async save with coroutine? it would have to copy or lock + * the surface. */ + ppm_save(filename, surface, &err); + + if (err) { + qmp_return_error(ret, err); + } else { + qmp_screendump_return(ret); + } +} + void graphic_hw_update_done(QemuConsole *con) { + struct qmp_screendump *dump, *next; + + QLIST_FOREACH_SAFE(dump, &con->qmp_screendumps, link, next) { + qmp_screendump_finish(con, dump->filename, dump->ret); + g_free(dump->filename); + QLIST_REMOVE(dump, link); + g_free(dump); + } } bool graphic_hw_update(QemuConsole *con) @@ -345,7 +386,8 @@ write_err: goto out; } -void qmp_screendump(const char *filename, Error **errp) +/* this sync screendump may produce outdated dumps: use qmp instead */ +void hmp_screendump_sync(const char *filename, Error **errp) { QemuConsole *con = qemu_console_lookup_by_index(0); DisplaySurface *surface; @@ -360,6 +402,29 @@ void qmp_screendump(const char *filename, Error **errp) ppm_save(filename, surface, errp); } +void qmp_screendump(const char *filename, QmpReturn *qret) +{ + QemuConsole *con = qemu_console_lookup_by_index(0); + bool async; + Error *err = NULL; + + if (con == NULL) { + error_setg(&err, "There is no QemuConsole I can screendump from."); + qmp_return_error(qret, err); + return; + } + + async = graphic_hw_update(con); + if (async) { + struct qmp_screendump *dump = g_new(struct qmp_screendump, 1); + dump->filename = g_strdup(filename); + dump->ret = qret; + QLIST_INSERT_HEAD(&con->qmp_screendumps, dump, link); + } else { + qmp_screendump_finish(con, filename, qret); + } +} + void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata) { if (!con) { @@ -1235,6 +1300,7 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type, obj = object_new(TYPE_QEMU_CONSOLE); s = QEMU_CONSOLE(obj); s->head = head; + QLIST_INIT(&s->qmp_screendumps); object_property_add_link(obj, "device", TYPE_DEVICE, (Object **)&s->device, object_property_allow_set_link, diff --git a/include/ui/console.h b/include/ui/console.h index fd9f648..7c4f35b 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -75,6 +75,7 @@ struct MouseTransformInfo { }; void hmp_mouse_set(Monitor *mon, const QDict *qdict); +void hmp_screendump_sync(const char *filename, Error **errp); /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx constants) */ diff --git a/qapi-schema.json b/qapi-schema.json index 117ace8..80e9aeb 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3570,9 +3570,18 @@ # # Returns: Nothing on success # +# Note: the operation can be cancelled and the file not written if the +# client disconnects before completion. +# # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "screendump", "arguments": { "filename": "/tmp/image" }, id: X } +# <- { "return": {}, id: X } +# ## -{ 'command': 'screendump', 'data': {'filename': 'str'} } +{ 'command': 'screendump', 'data': {'filename': 'str'}, 'async': true } ##