xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Oleksandr Grytsov <al1img@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com,
	Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Subject: [PATCH v1 4/6] libxl: vkb add list and info functions
Date: Wed,  1 Nov 2017 17:05:05 +0200	[thread overview]
Message-ID: <1509548707-6134-5-git-send-email-al1img@gmail.com> (raw)
In-Reply-To: <1509548707-6134-1-git-send-email-al1img@gmail.com>

From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
---
 tools/libxl/libxl.h         |  10 ++++
 tools/libxl/libxl_types.idl |  11 ++++
 tools/libxl/libxl_utils.h   |   3 ++
 tools/libxl/libxl_vkb.c     | 129 ++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index acb73ce..f2f8442 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1950,6 +1950,16 @@ int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid,
                              const libxl_asyncop_how *ao_how)
                             LIBXL_EXTERNAL_CALLERS_ONLY;
 
+libxl_device_vkb *libxl_device_vkb_list(libxl_ctx *ctx,
+                                        uint32_t domid, int *num)
+                                        LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_vkb_list_free(libxl_device_vkb* list, int num)
+                                LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid,
+                             libxl_device_vkb *vkb,
+                             libxl_vkbinfo *vkbinfo)
+                             LIBXL_EXTERNAL_CALLERS_ONLY;
+
 /* Framebuffer */
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
                          const libxl_asyncop_how *ao_how)
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index c3876a2..d19af46 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -1015,6 +1015,17 @@ libxl_vsndinfo = Struct("vsndinfo", [
     ("pcms", Array(libxl_pcminfo, "num_vsnd_pcms"))
     ])
 
+libxl_vkbinfo = Struct("vkbinfo", [
+    ("backend", string),
+    ("backend_id", uint32),
+    ("frontend", string),
+    ("frontend_id", uint32),
+    ("devid", libxl_devid),
+    ("state", integer),
+    ("evtch", integer),
+    ("rref", integer)
+    ], dir=DIR_OUT)
+
 # NUMA node characteristics: size and free are how much memory it has, and how
 # much of it is free, respectively. dists is an array of distances from this
 # node to each other node.
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 5455752..44409af 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -79,6 +79,9 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
 int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid,
                                   int devid, libxl_device_usbctrl *usbctrl);
 
+int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid,
+                              int devid, libxl_device_vkb *vkb);
+
 int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid,
                                  int devid, libxl_device_vdispl *vdispl);
 
diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c
index 88ab186..72ae53d 100644
--- a/tools/libxl/libxl_vkb.c
+++ b/tools/libxl/libxl_vkb.c
@@ -13,6 +13,7 @@
  */
 
 #include "libxl_internal.h"
+#include <xen/io/kbdif.h>
 
 static int libxl__device_vkb_setdefault(libxl__gc *gc, uint32_t domid,
                                         libxl_device_vkb *vkb, bool hotplug)
@@ -62,6 +63,45 @@ static int libxl__set_xenstore_vkb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int libxl__vkb_from_xenstore(libxl__gc *gc, const char *libxl_path,
+                                    libxl_devid devid,
+                                    libxl_device_vkb *vkb)
+{
+    const char *be_path, *be_type, *fe_path;
+    int rc;
+
+    vkb->devid = devid;
+
+    rc = libxl__xs_read_mandatory(gc, XBT_NULL,
+                                  GCSPRINTF("%s/backend", libxl_path),
+                                  &be_path);
+    if (rc) goto out;
+
+    rc = libxl__xs_read_mandatory(gc, XBT_NULL,
+                                  GCSPRINTF("%s/frontend", libxl_path),
+                                  &fe_path);
+    if (rc) goto out;
+
+    rc = libxl__xs_read_mandatory(gc, XBT_NULL,
+                                  GCSPRINTF("%s/backend-type", libxl_path),
+                                  &be_type);
+    if (rc) goto out;
+
+    rc = libxl_vkb_backend_from_string(be_type, &vkb->backend_type);
+    if (rc) goto out;
+
+    vkb->id = xs_read(CTX->xsh, XBT_NULL, GCSPRINTF("%s/id", fe_path), NULL);
+
+    rc = libxl__backendpath_parse_domid(gc, be_path, &vkb->backend_domid);
+    if (rc) goto out;
+
+    rc = 0;
+
+out:
+
+    return rc;
+}
+
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
                          const libxl_asyncop_how *ao_how)
 {
@@ -79,19 +119,102 @@ out:
     return AO_INPROGRESS;
 }
 
+int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid,
+                              int devid, libxl_device_vkb *vkb)
+{
+    GC_INIT(ctx);
+
+    libxl_device_vkb *vkbs = NULL;
+    int n, i;
+    int rc;
+
+    libxl_device_vkb_init(vkb);
+
+    vkbs = libxl__device_list(gc, &libxl__vkb_devtype, domid, &n);
+
+    if (!vkbs) { rc = ERROR_NOTFOUND; goto out; }
+
+    for (i = 0; i < n; ++i) {
+        if (devid == vkbs[i].devid) {
+            libxl_device_vkb_copy(ctx, vkb, &vkbs[i]);
+            rc = 0;
+            goto out;
+        }
+    }
+
+    rc = ERROR_NOTFOUND;
+
+out:
+
+    if (vkbs)
+        libxl__device_list_free(&libxl__vkb_devtype, vkbs, n);
+
+    GC_FREE;
+    return rc;
+}
+
+int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid,
+                             libxl_device_vkb *vkb,
+                             libxl_vkbinfo *info)
+{
+    GC_INIT(ctx);
+    char *libxl_path, *dompath, *devpath;
+    char *val;
+    int rc;
+
+    libxl_vkbinfo_init(info);
+    dompath = libxl__xs_get_dompath(gc, domid);
+    info->devid = vkb->devid;
+
+    devpath = GCSPRINTF("%s/device/vkbd/%d", dompath, info->devid);
+    libxl_path = GCSPRINTF("%s/device/vkbd/%d",
+                           libxl__xs_libxl_path(gc, domid),
+                           info->devid);
+    info->backend = xs_read(ctx->xsh, XBT_NULL,
+                            GCSPRINTF("%s/backend", libxl_path),
+                            NULL);
+    if (!info->backend) { rc = ERROR_FAIL; goto out; }
+
+    rc = libxl__backendpath_parse_domid(gc, info->backend, &info->backend_id);
+    if (rc) goto out;
+
+    val = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", devpath));
+    info->state = val ? strtoul(val, NULL, 10) : -1;
+
+    info->frontend = xs_read(ctx->xsh, XBT_NULL,
+                             GCSPRINTF("%s/frontend", libxl_path),
+                             NULL);
+    info->frontend_id = domid;
+
+    val = libxl__xs_read(gc, XBT_NULL,
+          GCSPRINTF("%s/"XENKBD_FIELD_EVT_CHANNEL, devpath));
+    info->evtch = val ? strtoul(val, NULL, 10) : -1;
+
+    val = libxl__xs_read(gc, XBT_NULL,
+          GCSPRINTF("%s/"XENKBD_FIELD_RING_GREF, devpath));
+    info->rref = val ? strtoul(val, NULL, 10) : -1;
+
+    rc = 0;
+
+out:
+     GC_FREE;
+     return rc;
+}
+
 static LIBXL_DEFINE_UPDATE_DEVID(vkb, "vkbd")
 
 #define libxl__add_vkbs NULL
-#define libxl_device_vkb_list NULL
 #define libxl_device_vkb_compare NULL
 
+LIBXL_DEFINE_DEVICE_LIST(vkb)
 LIBXL_DEFINE_DEVICE_REMOVE(vkb)
 
-DEFINE_DEVICE_TYPE_STRUCT_X(vkb, vkb, vkbd
+DEFINE_DEVICE_TYPE_STRUCT_X(vkb, vkb, vkbd,
     .skip_attach = 1,
     .dm_needed   = (device_dm_needed_fn_t)libxl__device_vkb_dm_needed,
     .set_xenstore_config   = (device_set_xenstore_config_fn_t)
-                             libxl__set_xenstore_vkb
+                             libxl__set_xenstore_vkb,
+    .from_xenstore = (device_from_xenstore_fn_t)libxl__vkb_from_xenstore
 );
 
 /*
-- 
2.7.4


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

  parent reply	other threads:[~2017-11-01 15:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01 15:05 [PATCH v1 0/6] libxl: create standalone vkb device Oleksandr Grytsov
2017-11-01 15:05 ` [PATCH v1 1/6] libxl: move vkb device to libxl_vkb.c Oleksandr Grytsov
2017-11-01 15:05 ` [PATCH v1 2/6] libxl: fix vkb XS entry and type Oleksandr Grytsov
2017-11-01 15:05 ` [PATCH v1 3/6] libxl: add backend type and id to vkb Oleksandr Grytsov
2018-02-06 14:25   ` Wei Liu
2018-02-06 16:45     ` Oleksandr Grytsov
2018-02-06 16:54       ` Wei Liu
2017-11-01 15:05 ` Oleksandr Grytsov [this message]
2018-02-06 14:26   ` [PATCH v1 4/6] libxl: vkb add list and info functions Wei Liu
2018-02-06 14:27   ` Wei Liu
2017-11-01 15:05 ` [PATCH v1 5/6] xl: add vkb config parser and CLI Oleksandr Grytsov
2018-02-06 14:27   ` Wei Liu
2017-11-01 15:05 ` [PATCH v1 6/6] docs: add vkb device to xl.cfg and xl Oleksandr Grytsov
2018-02-06 14:28   ` Wei Liu
2017-11-14 12:39 ` [PATCH v1 0/6] libxl: create standalone vkb device Oleksandr Grytsov
2017-11-20 13:44   ` Oleksandr Grytsov
2018-01-09 11:31     ` Oleksandr Grytsov
2018-02-05 11:03       ` Oleksandr Grytsov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509548707-6134-5-git-send-email-al1img@gmail.com \
    --to=al1img@gmail.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=oleksandr_grytsov@epam.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).