mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
xl: add vkb config parser and CLI
Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com> Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
1 parent
b29a93d323
commit
a15166af7c
6 files changed
+243
-2
No files matched your search
+1
-1
@@ -22,7 +22,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o
|
||||
XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o
|
||||
XL_OBJS += xl_info.o xl_console.o xl_misc.o
|
||||
XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o
|
||||
XL_OBJS += xl_vdispl.o xl_vsnd.o
|
||||
XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o
|
||||
|
||||
$(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
|
||||
$(XL_OBJS): CFLAGS += $(CFLAGS_XL)
|
||||
|
||||
@@ -173,6 +173,9 @@ int main_vdispldetach(int argc, char **argv);
|
||||
int main_vsndattach(int argc, char **argv);
|
||||
int main_vsndlist(int argc, char **argv);
|
||||
int main_vsnddetach(int argc, char **argv);
|
||||
int main_vkbattach(int argc, char **argv);
|
||||
int main_vkblist(int argc, char **argv);
|
||||
int main_vkbdetach(int argc, char **argv);
|
||||
int main_usbctrl_attach(int argc, char **argv);
|
||||
int main_usbctrl_detach(int argc, char **argv);
|
||||
int main_usbdev_attach(int argc, char **argv);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <libxl.h>
|
||||
|
||||
#include "xl.h"
|
||||
|
||||
struct cmd_spec cmd_table[] = {
|
||||
@@ -380,6 +381,21 @@ struct cmd_spec cmd_table[] = {
|
||||
"Destroy a domain's virtual TPM device",
|
||||
"<Domain> <DevId|uuid>",
|
||||
},
|
||||
{ "vkb-attach",
|
||||
&main_vkbattach, 1, 1,
|
||||
"Create a new virtual keyboard device",
|
||||
"<Domain> <vkb-spec-component(s)>...",
|
||||
},
|
||||
{ "vkb-list",
|
||||
&main_vkblist, 0, 0,
|
||||
"List virtual keyboard devices for a domain",
|
||||
"<Domain(s)>",
|
||||
},
|
||||
{ "vkb-detach",
|
||||
&main_vkbdetach, 0, 1,
|
||||
"Destroy a domain's virtual keyboard device",
|
||||
"<Domain> <DevId>",
|
||||
},
|
||||
{ "vdispl-attach",
|
||||
&main_vdisplattach, 1, 1,
|
||||
"Create a new virtual display device",
|
||||
|
||||
+75
-1
@@ -20,6 +20,7 @@
|
||||
#include <xen/hvm/e820.h>
|
||||
#include <xen/hvm/params.h>
|
||||
#include <xen/io/sndif.h>
|
||||
#include <xen/io/kbdif.h>
|
||||
|
||||
#include <libxl.h>
|
||||
#include <libxl_utils.h>
|
||||
@@ -1095,6 +1096,77 @@ static void parse_vsnd_config(const XLU_Config *config,
|
||||
}
|
||||
}
|
||||
|
||||
int parse_vkb_config(libxl_device_vkb *vkb, char *token)
|
||||
{
|
||||
char *oparg;
|
||||
|
||||
if (MATCH_OPTION("backend", token, oparg)) {
|
||||
vkb->backend_domname = strdup(oparg);
|
||||
} else if (MATCH_OPTION("backend-type", token, oparg)) {
|
||||
libxl_vkb_backend backend_type;
|
||||
if (libxl_vkb_backend_from_string(oparg, &backend_type)) {
|
||||
fprintf(stderr, "Unknown backend_type \"%s\" in vkb spec\n",
|
||||
oparg);
|
||||
return -1;
|
||||
}
|
||||
vkb->backend_type = backend_type;
|
||||
} else if (MATCH_OPTION(XENKBD_FIELD_UNIQUE_ID, token, oparg)) {
|
||||
vkb->unique_id = strdup(oparg);
|
||||
} else {
|
||||
fprintf(stderr, "Unknown string \"%s\" in vkb spec\n", token);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void parse_vkb_list(const XLU_Config *config,
|
||||
libxl_domain_config *d_config)
|
||||
{
|
||||
XLU_ConfigList *vkbs;
|
||||
const char *item;
|
||||
char *buf = NULL;
|
||||
int rc;
|
||||
|
||||
if (!xlu_cfg_get_list (config, "vkb", &vkbs, 0, 0)) {
|
||||
int entry = 0;
|
||||
while ((item = xlu_cfg_get_listitem(vkbs, entry)) != NULL) {
|
||||
libxl_device_vkb *vkb;
|
||||
char *p;
|
||||
|
||||
vkb = ARRAY_EXTEND_INIT(d_config->vkbs,
|
||||
d_config->num_vkbs,
|
||||
libxl_device_vkb_init);
|
||||
|
||||
buf = strdup(item);
|
||||
|
||||
p = strtok (buf, ",");
|
||||
while (p != NULL)
|
||||
{
|
||||
while (*p == ' ') p++;
|
||||
|
||||
rc = parse_vkb_config(vkb, p);
|
||||
if (rc) goto out;
|
||||
|
||||
p = strtok (NULL, ",");
|
||||
}
|
||||
|
||||
if (vkb->backend_type == LIBXL_VKB_BACKEND_UNKNOWN) {
|
||||
fprintf(stderr, "backend-type should be set in vkb spec\n");
|
||||
rc = -1; goto out;
|
||||
}
|
||||
|
||||
entry++;
|
||||
}
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
free(buf);
|
||||
if (rc) exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void parse_config_data(const char *config_source,
|
||||
const char *config_data,
|
||||
int config_len,
|
||||
@@ -2577,7 +2649,9 @@ skip_usbdev:
|
||||
"Unknown gic_version \"%s\" specified\n", buf);
|
||||
exit(-ERROR_FAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parse_vkb_list(config, d_config);
|
||||
|
||||
xlu_cfg_destroy(config);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ int parse_cpurange(const char *cpu, libxl_bitmap *cpumap);
|
||||
int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token);
|
||||
int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token);
|
||||
int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec);
|
||||
int parse_vkb_config(libxl_device_vkb *vkb, char *token);
|
||||
|
||||
int match_option_size(const char *prefix, size_t len,
|
||||
char *arg, char **argopt);
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2016 EPAM Systems Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; version 2.1 only. with the special
|
||||
* exception on linking described in file LICENSE.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libxl.h>
|
||||
#include <libxl_utils.h>
|
||||
#include <libxlutil.h>
|
||||
|
||||
#include "xl.h"
|
||||
#include "xl_utils.h"
|
||||
#include "xl_parse.h"
|
||||
|
||||
int main_vkbattach(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
int rc;
|
||||
uint32_t domid;
|
||||
libxl_device_vkb vkb;
|
||||
|
||||
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-attach", 2) {
|
||||
/* No options */
|
||||
}
|
||||
|
||||
libxl_device_vkb_init(&vkb);
|
||||
domid = find_domain(argv[optind++]);
|
||||
|
||||
for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) {
|
||||
rc = parse_vkb_config(&vkb, *argv);
|
||||
if (rc) goto out;
|
||||
}
|
||||
|
||||
if (vkb.backend_type == LIBXL_VKB_BACKEND_UNKNOWN) {
|
||||
fprintf(stderr, "backend-type should be set\n");
|
||||
rc = ERROR_FAIL; goto out;
|
||||
}
|
||||
|
||||
if (dryrun_only) {
|
||||
char *json = libxl_device_vkb_to_json(ctx, &vkb);
|
||||
printf("vkb: %s\n", json);
|
||||
free(json);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (libxl_device_vkb_add(ctx, domid, &vkb, 0)) {
|
||||
fprintf(stderr, "libxl_device_vkb_add failed.\n");
|
||||
rc = ERROR_FAIL; goto out;
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
libxl_device_vkb_dispose(&vkb);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main_vkblist(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
libxl_device_vkb *vkbs;
|
||||
libxl_vkbinfo vkbinfo;
|
||||
int nb, i;
|
||||
|
||||
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-list", 1) {
|
||||
/* No options */
|
||||
}
|
||||
|
||||
/* Idx BE Hdl Sta evch ref ID BE-type BE-path */
|
||||
printf("%-3s %-2s %-6s %-5s %-6s %6s %-10s %-10s %-30s\n",
|
||||
"Idx", "BE", "handle", "state", "evt-ch", "ref",
|
||||
"ID", "BE-type", "BE-path");
|
||||
for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
|
||||
uint32_t domid = find_domain(*argv);
|
||||
vkbs = libxl_device_vkb_list(ctx, domid, &nb);
|
||||
if (!vkbs) {
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < nb; ++i) {
|
||||
if (libxl_device_vkb_getinfo(ctx, domid, &vkbs[i], &vkbinfo) == 0) {
|
||||
printf("%-3d %-2d %6d %5d %6d %6d %-10s %-10s %-30s\n",
|
||||
vkbinfo.devid, vkbinfo.backend_id,
|
||||
vkbinfo.devid, vkbinfo.state, vkbinfo.evtch,
|
||||
vkbinfo.rref, vkbs[i].unique_id,
|
||||
libxl_vkb_backend_to_string(vkbs[i].backend_type),
|
||||
vkbinfo.backend);
|
||||
libxl_vkbinfo_dispose(&vkbinfo);
|
||||
}
|
||||
}
|
||||
libxl_device_vkb_list_free(vkbs, nb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main_vkbdetach(int argc, char **argv)
|
||||
{
|
||||
uint32_t domid, devid;
|
||||
int opt, rc;
|
||||
libxl_device_vkb vkb;
|
||||
|
||||
SWITCH_FOREACH_OPT(opt, "", NULL, "vkb-detach", 2) {
|
||||
/* No options */
|
||||
}
|
||||
|
||||
domid = find_domain(argv[optind++]);
|
||||
devid = atoi(argv[optind++]);
|
||||
|
||||
libxl_device_vkb_init(&vkb);
|
||||
|
||||
if (libxl_devid_to_device_vkb(ctx, domid, devid, &vkb)) {
|
||||
fprintf(stderr, "Error: Device %d not connected.\n", devid);
|
||||
rc = ERROR_FAIL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = libxl_device_vkb_remove(ctx, domid, &vkb, 0);
|
||||
if (rc) {
|
||||
fprintf(stderr, "libxl_device_vkb_remove failed.\n");
|
||||
rc = ERROR_FAIL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
libxl_device_vkb_dispose(&vkb);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: C
|
||||
* c-basic-offset: 4
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*/
|
||||