[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 23/25] console: make screendump async
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v2 23/25] console: make screendump async |
Date: |
Wed, 18 Jan 2017 20:03:30 +0400 |
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 <address@hidden>
---
qapi-schema.json | 5 +++-
include/ui/console.h | 1 +
hmp.c | 2 +-
ui/console.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index 2e7c96c122..2af8661357 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4686,6 +4686,9 @@
#
# 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:
@@ -4695,7 +4698,7 @@
# <- { "return": {} }
#
##
-{ 'command': 'screendump', 'data': {'filename': 'str'} }
+{ 'command': 'screendump', 'data': {'filename': 'str'}, 'async': true }
##
diff --git a/include/ui/console.h b/include/ui/console.h
index e2d4f0df0d..4199e7008a 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/hmp.c b/hmp.c
index 8522efea26..6586247a31 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1917,7 +1917,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 46ad6abd94..199296525c 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;
@@ -163,6 +169,8 @@ struct QemuConsole {
QEMUFIFO out_fifo;
uint8_t out_fifo_buf[16];
QEMUTimer *kbd_timer;
+
+ QLIST_HEAD(, qmp_screendump) qmp_screendumps;
};
struct DisplayState {
@@ -188,6 +196,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)
{
@@ -254,8 +264,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)
@@ -356,7 +397,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;
@@ -371,6 +413,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) {
@@ -1248,6 +1313,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,
--
2.11.0.295.gd7dffce1c
- [Qemu-devel] [PATCH v2 13/25] monitor: add 'async' capability, (continued)
- [Qemu-devel] [PATCH v2 13/25] monitor: add 'async' capability, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 14/25] monitor: add !qmp pre-conditions, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 15/25] monitor: suspend when running async and client has no async, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 16/25] qmp: update qmp-spec about async capability, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 17/25] qtest: add qtest-timeout, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 19/25] tests: add tests for async and non-async clients, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 18/25] qtest: add qtest_init_qmp_caps(), Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 20/25] qapi: improve 'screendump' documentation, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 21/25] console: graphic_hw_update return true if async, Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 22/25] console: add graphic_hw_update_done(), Marc-André Lureau, 2017/01/18
- [Qemu-devel] [PATCH v2 23/25] console: make screendump async,
Marc-André Lureau <=
[Qemu-devel] [PATCH v2 24/25] qtest: add /qemu-qmp/screendump test, Marc-André Lureau, 2017/01/18
[Qemu-devel] [PATCH v2 25/25] qmp: move json-message-parser and check to QmpClient, Marc-André Lureau, 2017/01/18
Re: [Qemu-devel] [PATCH v2 00/25] qmp: add async command type, no-reply, 2017/01/18
Re: [Qemu-devel] [PATCH v2 00/25] qmp: add async command type, Stefan Hajnoczi, 2017/01/23