diff mbox

[v6,06/13] libxl: change p9 to use generec add function

Message ID 1505224098-19330-7-git-send-email-al1img@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Grytsov Sept. 12, 2017, 1:48 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_9pfs.c     | 59 ++++++++++++++++----------------------------
 tools/libxl/libxl_create.c   |  2 +-
 tools/libxl/libxl_internal.h |  7 +-----
 3 files changed, 23 insertions(+), 45 deletions(-)
diff mbox

Patch

diff --git a/tools/libxl/libxl_9pfs.c b/tools/libxl/libxl_9pfs.c
index 5443f7a..61d284c 100644
--- a/tools/libxl/libxl_9pfs.c
+++ b/tools/libxl/libxl_9pfs.c
@@ -17,12 +17,10 @@ 
 
 #include "libxl_internal.h"
 
-int libxl__device_p9_setdefault(libxl__gc *gc, libxl_device_p9 *p9)
+static int libxl__device_p9_setdefault(libxl__gc *gc, uint32_t domid,
+                                       libxl_device_p9 *p9, bool hotplug)
 {
-    int rc;
-
-    rc = libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
-    return rc;
+    return libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
 }
 
 static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
@@ -41,44 +39,29 @@  static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
 
 static LIBXL_DEFINE_UPDATE_DEVID(p9, "9pfs")
 
-int libxl__device_p9_add(libxl__gc *gc, uint32_t domid,
-                         libxl_device_p9 *p9)
+static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_p9 *p9,
+                                  flexarray_t *back, flexarray_t *front,
+                                  flexarray_t *ro_front)
 {
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    int rc;
-
-    rc = libxl__device_p9_setdefault(gc, p9);
-    if (rc) goto out;
-
-    front = flexarray_make(gc, 16, 1);
-    back = flexarray_make(gc, 16, 1);
-
-    rc = libxl__device_p9_update_devid(gc, domid, p9);
-    if (rc) goto out;
-
-    rc = libxl__device_from_p9(gc, domid, p9, &device);
-    if (rc != 0) goto out;
-
-    flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", domid));
-    flexarray_append_pair(back, "online", "1");
-    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
-    flexarray_append_pair(front, "backend-id",
-                          libxl__sprintf(gc, "%d", p9->backend_domid));
-    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
-    flexarray_append_pair(front, "tag", p9->tag);
     flexarray_append_pair(back, "path", p9->path);
     flexarray_append_pair(back, "security_model", p9->security_model);
 
-    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;
+    flexarray_append_pair(front, "tag", p9->tag);
+
+    return 0;
 }
 
+#define libxl__add_p9s NULL
+#define libxl_device_p9_list NULL
+#define libxl_device_p9_compare NULL
+
 LIBXL_DEFINE_DEVICE_REMOVE(p9)
 
+DEFINE_DEVICE_TYPE_STRUCT(p9,
+    .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_p9
+);
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index f20bbf9..26aa2a4 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1328,7 +1328,7 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
     }
 
     for (i = 0; i < d_config->num_p9s; i++)
-        libxl__device_p9_add(gc, domid, &d_config->p9s[i]);
+        libxl__device_add(gc, domid, &libxl__p9_devtype, &d_config->p9s[i]);
 
     switch (d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index c6f5868..87f6d32 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1251,8 +1251,6 @@  _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
 _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
-_hidden int libxl__device_p9_setdefault(libxl__gc *gc,
-                                        libxl_device_p9 *p9);
 
 _hidden const char *libxl__device_nic_devname(libxl__gc *gc,
                                               uint32_t domid,
@@ -2667,10 +2665,6 @@  _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid,
                                   libxl_device_vfb *vfb);
 
-/* Internal function to connect a 9pfs device */
-_hidden int libxl__device_p9_add(libxl__gc *gc, uint32_t domid,
-                                 libxl_device_p9 *p9);
-
 /* 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
@@ -3564,6 +3558,7 @@  extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];