[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH] libxl: add screendump API



Currently libvirt kvm can support domain screenshot but libxl
cannot. This patch is trying to add screendump API in libxl
by calling qmp 'screendump' command, so to support screenshot
for domains.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 tools/libxl/libxl.c          | 36 ++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h          |  9 +++++++++
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_qmp.c      |  8 ++++++++
 4 files changed, 55 insertions(+)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index bd3aac8..712ea5a 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -6824,6 +6824,42 @@ out:
     return rc;
 }
 
+int libxl_domain_screendump(libxl_ctx *ctx, uint32_t domid,
+                            const char *filename)
+{
+    GC_INIT(ctx);
+    char *pid;
+    int rc, dm_present;
+
+    switch (libxl__domain_type(gc, domid)) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        if (!libxl_get_stubdom_id(ctx, domid))
+            dm_present = 1;
+        else
+            dm_present = 0;
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+        pid = libxl__xs_read(gc, XBT_NULL, 
GCSPRINTF("/local/domain/%d/image/device-model-pid", domid));
+        dm_present = (pid != NULL);
+        break;
+    case LIBXL_DOMAIN_TYPE_INVALID:
+    default:
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (dm_present) {
+        rc = libxl__qmp_screendump(gc, domid, filename);
+    } else {
+        LOG(ERROR, "Not supported");
+        rc = ERROR_FAIL;
+    }
+
+out:
+    GC_FREE;
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 6b73848..f1fb5b7 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -218,6 +218,12 @@
 #define LIBXL_HAVE_SOFT_RESET 1
 
 /*
+ * LIBXL_HAVE_SCREENDUMP indicates that libxl supports taking
+ * screenshot for domains.
+ */
+#define LIBXL_HAVE_SCREENDUMP 1
+
+/*
  * libxl ABI compatibility
  *
  * The only guarantee which libxl makes regarding ABI compatibility
@@ -1657,6 +1663,9 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
 int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
 
+int libxl_domain_screendump(libxl_ctx *ctx, uint32_t domid,
+                            const char *filename);
+
 typedef struct libxl__xen_console_reader libxl_xen_console_reader;
 
 libxl_xen_console_reader *
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 58d07cd..230da23 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1734,6 +1734,8 @@ typedef struct libxl__qmp_handler libxl__qmp_handler;
  */
 _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc,
                                                   uint32_t domid);
+_hidden int libxl__qmp_screendump(libxl__gc *gc, int domid,
+                                  const char *filename);
 /* ask to QEMU the serial port information and store it in xenstore. */
 _hidden int libxl__qmp_query_serial(libxl__qmp_handler *qmp);
 _hidden int libxl__qmp_pci_add(libxl__gc *gc, int d, libxl_device_pci *pcidev);
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index f798de7..835b43d 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -968,6 +968,14 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx)
     return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL);
 }
 
+int libxl__qmp_screendump(libxl__gc *gc, int domid, const char *filename)
+{
+    libxl__json_object *args = NULL;
+
+    qmp_parameters_add_string(gc, &args, "filename", filename);
+    return qmp_run_command(gc, domid, "screendump", args, NULL, NULL);
+}
+
 int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_config *guest_config)
 {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.