libxl: add screendump API
RFC PATCH 1/1 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 <[email protected]>
--- 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(+)
tools/libxl/libxl.c +36 -0
@@ -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
tools/libxl/libxl.h +9 -0
@@ -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 *
tools/libxl/libxl_internal.h +2 -0
@@ -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);
tools/libxl/libxl_qmp.c +8 -0
@@ -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) {
Signature · 1 line
2.1.4