diff mbox

[v1,3/6] libxl: add backend type and id to vkb

Message ID 1509548707-6134-4-git-send-email-al1img@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Grytsov Nov. 1, 2017, 3:05 p.m. UTC
From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

New field backend_type is added to vkb device
in order to have QEMU and user space backend
simultaneously. Each vkb backend shall read
appropriate XS entry and service only own
frontends.
Id is a string field which used by the backend
to indentify the frontend.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
---
 tools/libxl/libxl_create.c  |  3 +++
 tools/libxl/libxl_dm.c      |  1 +
 tools/libxl/libxl_types.idl |  8 ++++++++
 tools/libxl/libxl_vkb.c     | 33 ++++++++++++++++++++++++++++++++-
 4 files changed, 44 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index f813114..60d8686 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1376,6 +1376,9 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         for (i = 0; i < d_config->num_vfbs; i++) {
             libxl__device_add(gc, domid, &libxl__vfb_devtype,
                               &d_config->vfbs[i]);
+        }
+
+        for (i = 0; i < d_config->num_vkbs; i++) {
             libxl__device_add(gc, domid, &libxl__vkb_devtype,
                               &d_config->vkbs[i]);
         }
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 98f89a9..f07de35 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1728,6 +1728,7 @@  static int libxl__vfb_and_vkb_from_hvm_guest_config(libxl__gc *gc,
 
     vkb->backend_domid = 0;
     vkb->devid = 0;
+
     return 0;
 }
 
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index cd0c06f..c3876a2 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -240,6 +240,12 @@  libxl_checkpointed_stream = Enumeration("checkpointed_stream", [
     (2, "COLO"),
     ])
 
+libxl_vkb_backend = Enumeration("vkb_backend", [
+    (0, "UNKNOWN"),
+    (1, "QEMU"),
+    (2, "LINUX")
+    ])
+
 #
 # Complex libxl types
 #
@@ -603,6 +609,8 @@  libxl_device_vkb = Struct("device_vkb", [
     ("backend_domid", libxl_domid),
     ("backend_domname", string),
     ("devid", libxl_devid),
+    ("backend_type", libxl_vkb_backend),
+    ("id", string)
     ])
 
 libxl_device_disk = Struct("device_disk", [
diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c
index ea6fca8..88ab186 100644
--- a/tools/libxl/libxl_vkb.c
+++ b/tools/libxl/libxl_vkb.c
@@ -17,6 +17,10 @@ 
 static int libxl__device_vkb_setdefault(libxl__gc *gc, uint32_t domid,
                                         libxl_device_vkb *vkb, bool hotplug)
 {
+    if (vkb->backend_type == LIBXL_VKB_BACKEND_UNKNOWN) {
+        vkb->backend_type = LIBXL_VKB_BACKEND_QEMU;
+    }
+
     return libxl__resolve_domid(gc, vkb->backend_domname, &vkb->backend_domid);
 }
 
@@ -34,6 +38,30 @@  static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int libxl__device_vkb_dm_needed(libxl_device_vkb *vkb, uint32_t domid)
+{
+   if (vkb->backend_type == LIBXL_VKB_BACKEND_QEMU) {
+        return 1;
+   }
+
+    return 0;
+}
+
+static int libxl__set_xenstore_vkb(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_vkb *vkb,
+                                   flexarray_t *back, flexarray_t *front,
+                                   flexarray_t *ro_front)
+{
+    if (vkb->id) {
+        flexarray_append_pair(front, "id", vkb->id);
+    }
+
+    flexarray_append_pair(back, "backend-type",
+                          (char *)libxl_vkb_backend_to_string(vkb->backend_type));
+
+    return 0;
+}
+
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
                          const libxl_asyncop_how *ao_how)
 {
@@ -60,7 +88,10 @@  static LIBXL_DEFINE_UPDATE_DEVID(vkb, "vkbd")
 LIBXL_DEFINE_DEVICE_REMOVE(vkb)
 
 DEFINE_DEVICE_TYPE_STRUCT_X(vkb, vkb, vkbd
-    .skip_attach = 1
+    .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
 );
 
 /*