#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>
}
}
+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,
"Unknown gic_version \"%s\" specified\n", buf);
exit(-ERROR_FAIL);
}
- }
+ }
+
+ parse_vkb_list(config, d_config);
xlu_cfg_destroy(config);
}
--- /dev/null
+/*
+ * 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:
+ */