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

[Xen-devel] [PATCH v1 5/6] xl: add vkb config parser and CLI



From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
---
 tools/xl/Makefile      |   2 +-
 tools/xl/xl.h          |   3 ++
 tools/xl/xl_cmdtable.c |  15 ++++++
 tools/xl/xl_parse.c    |  75 +++++++++++++++++++++++++-
 tools/xl/xl_parse.h    |   2 +-
 tools/xl/xl_vkb.c      | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 236 insertions(+), 3 deletions(-)
 create mode 100644 tools/xl/xl_vkb.c

diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index 66bdbde..2769295 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -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)
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 703caa6..826e9c1 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -170,6 +170,9 @@ int main_vtpmdetach(int argc, char **argv);
 int main_vdisplattach(int argc, char **argv);
 int main_vdispllist(int argc, char **argv);
 int main_vdispldetach(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_vsndattach(int argc, char **argv);
 int main_vsndlist(int argc, char **argv);
 int main_vsnddetach(int argc, char **argv);
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 8e162ce..8f076d0 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -378,6 +378,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> [id=<InputId>] [backend-type=<BackendType>] 
[backend=<BackDomain>]",
+    },
+    { "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",
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index d4c2efb..e018337 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -1099,6 +1099,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("id", token, oparg)) {
+        vkb->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,
@@ -2419,7 +2490,9 @@ skip_usbdev:
                     "Unknown gic_version \"%s\" specified\n", buf);
             exit(-ERROR_FAIL);
         }
-     }
+    }
+
+    parse_vkb_list(config, d_config);
 
     xlu_cfg_destroy(config);
 }
diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h
index 9a948ea..19f453a 100644
--- a/tools/xl/xl_parse.h
+++ b/tools/xl/xl_parse.h
@@ -35,7 +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);
 #define MATCH_OPTION(prefix, arg, oparg) \
diff --git a/tools/xl/xl_vkb.c b/tools/xl/xl_vkb.c
new file mode 100644
index 0000000..4b09903
--- /dev/null
+++ b/tools/xl/xl_vkb.c
@@ -0,0 +1,142 @@
+/*
+ * 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 (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].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:
+ */
-- 
2.7.4


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

 


Rackspace

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