218e99
From b0abe7c2c3873172eee6020c49ca3a44567bb645 Mon Sep 17 00:00:00 2001
218e99
From: Gerd Hoffmann <kraxel@redhat.com>
218e99
Date: Wed, 7 Aug 2013 09:12:44 +0200
218e99
Subject: add qxl_screendump monitor command
218e99
218e99
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
218e99
Message-id: <1375866764-17766-2-git-send-email-kraxel@redhat.com>
218e99
Patchwork-id: 53033
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH 1/1] add qxl_screendump monitor command
218e99
Bugzilla: 903910
218e99
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
218e99
218e99
This patch ports the rhel-6 specific qxl_screendump command to rhel-7.
218e99
qxl_screendump takes the device id as additional argument and thus can
218e99
be used to take screenshots from non-primary displays.
218e99
218e99
The plan to get that functionality upstream in time failed, so we go for
218e99
plan b and carry forward the rhel-6 specific qxl_screendump command.
218e99
Thanks to the major console subsystem cleanups which made it upstream
218e99
the implementation is (a) alot less hackier than the rhel-6 one and (b)
218e99
not qxl-specific any more.  Given that qxl is the only graphic device
218e99
which can work as secondary vga card the later is only a theoretical
218e99
benefit though ;)
218e99
218e99
RHEL-6 commit: 1c6074d107dff93c7c7b0edfb5da871504802946
218e99
218e99
bugzilla: #903910 - RHEL7 does not have equivalent functionality for
218e99
                    __com.redhat_qxl_screendump
218e99
218e99
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
218e99
218e99
diff --git a/hmp-commands.hx b/hmp-commands.hx
218e99
index 4f5a3fd..5cd6368 100644
218e99
--- a/hmp-commands.hx
218e99
+++ b/hmp-commands.hx
218e99
@@ -242,6 +242,13 @@ ETEXI
218e99
         .help       = "save screen into PPM image 'filename'",
218e99
         .mhandler.cmd = hmp_screen_dump,
218e99
     },
218e99
+    {
218e99
+        .name       = "__com.redhat_qxl_screendump",
218e99
+        .args_type  = "id:s,filename:F",
218e99
+        .params     = "id filename",
218e99
+        .help       = "save screen from qxl device 'id' into PPM image 'filename'",
218e99
+        .mhandler.cmd = hmp___com_redhat_qxl_screen_dump,
218e99
+    },
218e99
 
218e99
 STEXI
218e99
 @item screendump @var{filename}
218e99
diff --git a/hmp.c b/hmp.c
218e99
index 4fb76ec..3b3e7c7 100644
218e99
--- a/hmp.c
218e99
+++ b/hmp.c
218e99
@@ -1328,6 +1328,16 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict)
218e99
     hmp_handle_error(mon, &err);
218e99
 }
218e99
 
218e99
+void hmp___com_redhat_qxl_screen_dump(Monitor *mon, const QDict *qdict)
218e99
+{
218e99
+    const char *id = qdict_get_str(qdict, "id");
218e99
+    const char *filename = qdict_get_str(qdict, "filename");
218e99
+    Error *err = NULL;
218e99
+
218e99
+    qmp___com_redhat_qxl_screendump(id, filename, &err);
218e99
+    hmp_handle_error(mon, &err);
218e99
+}
218e99
+
218e99
 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
218e99
 {
218e99
     const char *uri = qdict_get_str(qdict, "uri");
218e99
diff --git a/hmp.h b/hmp.h
218e99
index 95fe76e..9b2c9ce 100644
218e99
--- a/hmp.h
218e99
+++ b/hmp.h
218e99
@@ -80,6 +80,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict);
218e99
 void hmp_closefd(Monitor *mon, const QDict *qdict);
218e99
 void hmp_send_key(Monitor *mon, const QDict *qdict);
218e99
 void hmp_screen_dump(Monitor *mon, const QDict *qdict);
218e99
+void hmp___com_redhat_qxl_screen_dump(Monitor *mon, const QDict *qdict);
218e99
 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict);
218e99
 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
218e99
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
218e99
diff --git a/qapi-schema.json b/qapi-schema.json
218e99
index 537f1d1..54a802d 100644
218e99
--- a/qapi-schema.json
218e99
+++ b/qapi-schema.json
218e99
@@ -3123,6 +3123,21 @@
218e99
 { 'command': 'screendump', 'data': {'filename': 'str'} }
218e99
 
218e99
 ##
218e99
+# @__com.redhat_qxl_screendump:
218e99
+#
218e99
+# Write a PPM of secondary qxl devices to a file.
218e99
+#
218e99
+# @id: qxl device id
218e99
+# @filename: the path of a new PPM file to store the image
218e99
+#
218e99
+# Returns: Nothing on success
218e99
+#
218e99
+# Since: never (rhel-only, not upstream)
218e99
+##
218e99
+{ 'command': '__com.redhat_qxl_screendump', 'data': { 'id' : 'str',
218e99
+                                                      'filename': 'str' } }
218e99
+
218e99
+##
218e99
 # @nbd-server-start:
218e99
 #
218e99
 # Start an NBD server listening on the given host and port.  Block
218e99
diff --git a/qmp-commands.hx b/qmp-commands.hx
218e99
index ffd130e..de5f394 100644
218e99
--- a/qmp-commands.hx
218e99
+++ b/qmp-commands.hx
218e99
@@ -148,6 +148,11 @@ EQMP
218e99
         .args_type  = "filename:F",
218e99
         .mhandler.cmd_new = qmp_marshal_input_screendump,
218e99
     },
218e99
+    {
218e99
+        .name       = "__com.redhat_qxl_screendump",
218e99
+        .args_type  = "id:s,filename:F",
218e99
+        .mhandler.cmd_new = qmp_marshal_input___com_redhat_qxl_screendump,
218e99
+    },
218e99
 
218e99
 SQMP
218e99
 screendump
218e99
diff --git a/ui/console.c b/ui/console.c
218e99
index 28bba6d..d422083 100644
218e99
--- a/ui/console.c
218e99
+++ b/ui/console.c
218e99
@@ -328,6 +328,29 @@ void qmp_screendump(const char *filename, Error **errp)
218e99
     ppm_save(filename, surface, errp);
218e99
 }
218e99
 
218e99
+void qmp___com_redhat_qxl_screendump(const char *id, const char *filename, Error **errp)
218e99
+{
218e99
+    DeviceState *dev;
218e99
+    QemuConsole *con;
218e99
+    DisplaySurface *surface;
218e99
+
218e99
+    dev = qdev_find_recursive(sysbus_get_default(), id);
218e99
+    if (NULL == dev) {
218e99
+        error_set(errp, QERR_DEVICE_NOT_FOUND, id);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    con = qemu_console_lookup_by_device(dev);
218e99
+    if (con == NULL) {
218e99
+        error_setg(errp, "Device %s has no QemuConsole attached to it.", id);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    graphic_hw_update(con);
218e99
+    surface = qemu_console_surface(con);
218e99
+    ppm_save(filename, surface, errp);
218e99
+}
218e99
+
218e99
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata)
218e99
 {
218e99
     if (!con) {