diff mbox

[v5,08/12] libxl: change vfb to use generec add function

Message ID 1505150102-30806-9-git-send-email-al1img@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Grytsov Sept. 11, 2017, 5:14 p.m. UTC
From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_console.c  | 69 ++++++++++++--------------------------------
 tools/libxl/libxl_create.c   |  3 +-
 tools/libxl/libxl_dm.c       |  6 ++--
 tools/libxl/libxl_internal.h |  6 +---
 4 files changed, 25 insertions(+), 59 deletions(-)
diff mbox

Patch

diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index e4a0daf..6dcad8a 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -605,7 +605,8 @@  static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
 
 static LIBXL_DEFINE_UPDATE_DEVID(vkb, "vkb")
 
-int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb)
+static int libxl__device_vfb_setdefault(libxl__gc *gc, uint32_t domid,
+                                        libxl_device_vfb *vfb, bool hotplug)
 {
     int rc;
 
@@ -641,47 +642,13 @@  static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
-                         const libxl_asyncop_how *ao_how)
-{
-    AO_CREATE(ctx, domid, ao_how);
-    int rc;
-
-    rc = libxl__device_vfb_add(gc, domid, vfb);
-    if (rc) {
-        LOGD(ERROR, domid, "Unable to add vfb device");
-        goto out;
-    }
-
-out:
-    libxl__ao_complete(egc, ao, rc);
-    return AO_INPROGRESS;
-}
-
 static LIBXL_DEFINE_UPDATE_DEVID(vfb, "vfb")
 
-int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
+static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_vfb *vfb,
+                                  flexarray_t *back, flexarray_t *front,
+                                  flexarray_t *ro_front)
 {
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    int rc;
-
-    rc = libxl__device_vfb_setdefault(gc, vfb);
-    if (rc) goto out;
-
-    front = flexarray_make(gc, 16, 1);
-    back = flexarray_make(gc, 16, 1);
-
-    rc = libxl__device_vfb_update_devid(gc, domid, vfb);
-    if (rc) goto out;
-
-    rc = libxl__device_from_vfb(gc, domid, vfb, &device);
-    if (rc != 0) goto out;
-
-    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
-    flexarray_append_pair(back, "online", "1");
-    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
     flexarray_append_pair(back, "vnc",
                           libxl_defbool_val(vfb->vnc.enable) ? "1" : "0");
     flexarray_append_pair(back, "vnclisten", vfb->vnc.listen);
@@ -701,17 +668,7 @@  int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
         flexarray_append_pair(back, "display", vfb->sdl.display);
     }
 
-    flexarray_append_pair(front, "backend-id",
-                          GCSPRINTF("%d", vfb->backend_domid));
-    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
-
-    libxl__device_generic_add(gc, XBT_NULL, &device,
-                              libxl__xs_kvs_of_flexarray(gc, back),
-                              libxl__xs_kvs_of_flexarray(gc, front),
-                              NULL);
-    rc = 0;
-out:
-    return rc;
+    return 0;
 }
 
 /* The following functions are defined:
@@ -737,9 +694,21 @@  DEFINE_DEVICE_TYPE_STRUCT(vkb,
     .skip_attach = 1
 );
 
+#define libxl__add_vfbs NULL
+#define libxl_device_vfb_list NULL
+#define libxl_device_vfb_compare NULL
+
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
 
+DEFINE_DEVICE_TYPE_STRUCT(vfb,
+    .skip_attach = 1,
+    .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *,
+                                    flexarray_t *back, flexarray_t *front,
+                                    flexarray_t *ro_front))
+                           libxl__set_xenstore_vfb
+);
+
 libxl_xen_console_reader *
     libxl_xen_console_read_start(libxl_ctx *ctx, int clear)
 {
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 8c0c12d..70048fe 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1374,7 +1374,8 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device device;
 
         for (i = 0; i < d_config->num_vfbs; i++) {
-            libxl__device_vfb_add(gc, domid, &d_config->vfbs[i]);
+            libxl__device_add(gc, domid, &libxl__vfb_devtype,
+                              &d_config->vfbs[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 0712a34..275fabc 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1981,9 +1981,9 @@  static void spawn_stub_launch_dm(libxl__egc *egc,
             goto out;
     }
     if (dm_config->num_vfbs) {
-        ret = libxl__device_vfb_add(gc, dm_domid, &dm_config->vfbs[0]);
-        if (ret)
-            goto out;
+        ret = libxl__device_add(gc, dm_domid, &libxl__vfb_devtype,
+                                &dm_config->vfbs[0]);
+        if (ret) goto out;
     }
     if (dm_config->num_vkbs) {
         ret = libxl__device_add(gc, dm_domid, &libxl__vkb_devtype,
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index c2ef67f..6b21812 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1247,7 +1247,6 @@  _hidden int libxl__device_disk_setdefault(libxl__gc *gc, uint32_t domid,
                                           bool hotplug);
 _hidden int libxl__device_nic_setdefault(libxl__gc *gc, uint32_t domid,
                                          libxl_device_nic *nic, bool hotplug);
-_hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
 
@@ -2656,10 +2655,6 @@  struct libxl__multidev {
  * it's a valid state.
  */
 
-/* Internal function to connect a vfb device */
-_hidden int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vfb *vfb);
-
 /* Waits for the passed device to reach state XenbusStateInitWait.
  * This is not really useful by itself, but is important when executing
  * hotplug scripts, since we need to be sure the device is in the correct
@@ -3546,6 +3541,7 @@  static inline int *libxl__device_type_get_num(
     return (int *)((void *)d_config + dt->num_offset);
 }
 
+extern const struct libxl_device_type libxl__vfb_devtype;
 extern const struct libxl_device_type libxl__vkb_devtype;
 extern const struct libxl_device_type libxl__disk_devtype;
 extern const struct libxl_device_type libxl__nic_devtype;