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

[Xen-devel] [PATCH v1 3/4] libxl: move libxl__device_from_ to LIBXL_DEFINE_DEVICE_FROM_TYPE



From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>

LIBXL_DEFINE_DEVICE_FROM_TYPE uses libxl__..._devtype.type to
be assigned as device and backend type.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/libxl_9pfs.c     | 19 +++----------------
 tools/libxl/libxl_console.c  | 18 +++---------------
 tools/libxl/libxl_internal.h | 15 +++++++++++++++
 tools/libxl/libxl_nic.c      | 19 +++----------------
 tools/libxl/libxl_vdispl.c   | 20 ++++----------------
 tools/libxl/libxl_vtpm.c     | 21 ++++-----------------
 6 files changed, 32 insertions(+), 80 deletions(-)

diff --git a/tools/libxl/libxl_9pfs.c b/tools/libxl/libxl_9pfs.c
index 1298db1..e5c41e9 100644
--- a/tools/libxl/libxl_9pfs.c
+++ b/tools/libxl/libxl_9pfs.c
@@ -23,22 +23,6 @@ static int libxl__device_p9_setdefault(libxl__gc *gc, 
uint32_t domid,
     return libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
 }
 
-static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
-                                 libxl_device_p9 *p9,
-                                 libxl__device *device)
-{
-   device->backend_devid   = p9->devid;
-   device->backend_domid   = p9->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_9PFS;
-   device->devid           = p9->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_9PFS;
-
-   return 0;
-}
-
-static LIBXL_DEFINE_UPDATE_DEVID(p9)
-
 static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid,
                                   libxl_device_p9 *p9,
                                   flexarray_t *back, flexarray_t *front,
@@ -56,6 +40,9 @@ static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t 
domid,
 #define libxl_device_p9_list NULL
 #define libxl_device_p9_compare NULL
 
+static LIBXL_DEFINE_UPDATE_DEVID(p9)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(p9)
+
 LIBXL_DEFINE_DEVICE_REMOVE(p9)
 
 DEFINE_DEVICE_TYPE_STRUCT(p9, 9PFS,
diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 1a0eb05..39d8430 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -698,19 +698,6 @@ static int libxl__device_vfb_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vfb *vfb,
-                                  libxl__device *device)
-{
-    device->backend_devid = vfb->devid;
-    device->backend_domid = vfb->backend_domid;
-    device->backend_kind = LIBXL__DEVICE_KIND_VFB;
-    device->devid = vfb->devid;
-    device->domid = domid;
-    device->kind = LIBXL__DEVICE_KIND_VFB;
-    return 0;
-}
-
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
                          const libxl_asyncop_how *ao_how)
 {
@@ -728,8 +715,6 @@ out:
     return AO_INPROGRESS;
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(vfb)
-
 static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid,
                                    libxl_device_vfb *vfb,
                                   flexarray_t *back, flexarray_t *front,
@@ -784,6 +769,9 @@ DEFINE_DEVICE_TYPE_STRUCT(vkb, VKBD,
 #define libxl_device_vfb_list NULL
 #define libxl_device_vfb_compare NULL
 
+static LIBXL_DEFINE_UPDATE_DEVID(vfb)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vfb)
+
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index e9f3960..4f1e026 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3475,6 +3475,21 @@ _hidden void libxl__bootloader_run(libxl__egc*, 
libxl__bootloader_state *st);
         return 0;                                                       \
     }
 
+#define LIBXL_DEFINE_DEVICE_FROM_TYPE(name)                             \
+    int libxl__device_from_##name(libxl__gc *gc, uint32_t domid,        \
+                                  libxl_device_##name *type,            \
+                                  libxl__device *device)                \
+    {                                                                   \
+        device->backend_devid   = type->devid;                          \
+        device->backend_domid   = type->backend_domid;                  \
+        device->backend_kind    = libxl__##name##_devtype.type;         \
+        device->devid           = type->devid;                          \
+        device->domid           = domid;                                \
+        device->kind            = libxl__##name##_devtype.type;         \
+                                                                        \
+        return 0;                                                       \
+    }
+
 #define LIBXL_DEFINE_DEVICE_REMOVE(type)                                \
     LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, remove, 0)            \
     LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, destroy, 1)
diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c
index 4b1b131..e028fda 100644
--- a/tools/libxl/libxl_nic.c
+++ b/tools/libxl/libxl_nic.c
@@ -116,20 +116,6 @@ static int libxl__device_nic_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_nic *nic,
-                                  libxl__device *device)
-{
-    device->backend_devid    = nic->devid;
-    device->backend_domid    = nic->backend_domid;
-    device->backend_kind     = LIBXL__DEVICE_KIND_VIF;
-    device->devid            = nic->devid;
-    device->domid            = domid;
-    device->kind             = LIBXL__DEVICE_KIND_VIF;
-
-    return 0;
-}
-
 static void libxl__update_config_nic(libxl__gc *gc, libxl_device_nic *dst,
                                      const libxl_device_nic *src)
 {
@@ -138,8 +124,6 @@ static void libxl__update_config_nic(libxl__gc *gc, 
libxl_device_nic *dst,
     libxl_mac_copy(CTX, &dst->mac, &src->mac);
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(nic)
-
 static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
                                    libxl_device_nic *nic,
                                    flexarray_t *back, flexarray_t *front,
@@ -533,6 +517,9 @@ out:
     return ret;
 }
 
+static LIBXL_DEFINE_UPDATE_DEVID(nic)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(nic)
+
 LIBXL_DEFINE_DEVICE_ADD(nic)
 LIBXL_DEFINE_DEVICES_ADD(nic)
 LIBXL_DEFINE_DEVICE_REMOVE(nic)
diff --git a/tools/libxl/libxl_vdispl.c b/tools/libxl/libxl_vdispl.c
index 602e690..da5b10f 100644
--- a/tools/libxl/libxl_vdispl.c
+++ b/tools/libxl/libxl_vdispl.c
@@ -22,20 +22,6 @@ static int libxl__device_vdispl_setdefault(libxl__gc *gc, 
uint32_t domid,
                                 &vdispl->backend_domid);
 }
 
-static int libxl__device_from_vdispl(libxl__gc *gc, uint32_t domid,
-                                     libxl_device_vdispl *vdispl,
-                                     libxl__device *device)
-{
-   device->backend_devid   = vdispl->devid;
-   device->backend_domid   = vdispl->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_VDISPL;
-   device->devid           = vdispl->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_VDISPL;
-
-   return 0;
-}
-
 static int libxl__vdispl_from_xenstore(libxl__gc *gc, const char *libxl_path,
                                        libxl_devid devid,
                                        libxl_device_vdispl *vdispl)
@@ -243,10 +229,12 @@ out:
     return rc;
 }
 
-LIBXL_DEFINE_DEVICE_ADD(vdispl)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vdispl)
+static LIBXL_DEFINE_UPDATE_DEVID(vdispl)
 static LIBXL_DEFINE_DEVICES_ADD(vdispl)
+
+LIBXL_DEFINE_DEVICE_ADD(vdispl)
 LIBXL_DEFINE_DEVICE_REMOVE(vdispl)
-static LIBXL_DEFINE_UPDATE_DEVID(vdispl)
 LIBXL_DEFINE_DEVICE_LIST(vdispl)
 
 DEFINE_DEVICE_TYPE_STRUCT(vdispl, VDISPL,
diff --git a/tools/libxl/libxl_vtpm.c b/tools/libxl/libxl_vtpm.c
index f0a4610..7c91f99 100644
--- a/tools/libxl/libxl_vtpm.c
+++ b/tools/libxl/libxl_vtpm.c
@@ -28,20 +28,6 @@ static int libxl__device_vtpm_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t domid,
-                                   libxl_device_vtpm *vtpm,
-                                   libxl__device *device)
-{
-   device->backend_devid   = vtpm->devid;
-   device->backend_domid   = vtpm->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_VTPM;
-   device->devid           = vtpm->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_VTPM;
-
-   return 0;
-}
-
 static void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_vtpm *dst,
                                       libxl_device_vtpm *src)
 {
@@ -49,8 +35,6 @@ static void libxl__update_config_vtpm(libxl__gc *gc, 
libxl_device_vtpm *dst,
     libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(vtpm)
-
 static int libxl__set_xenstore_vtpm(libxl__gc *gc, uint32_t domid,
                                     libxl_device_vtpm *vtpm,
                                     flexarray_t *back, flexarray_t *front,
@@ -239,8 +223,11 @@ static void libxl_device_vtpm_update_config(libxl__gc *gc, 
void *d, void *s)
     libxl__update_config_vtpm(gc, d, s);
 }
 
-LIBXL_DEFINE_DEVICE_ADD(vtpm)
+static LIBXL_DEFINE_UPDATE_DEVID(vtpm)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vtpm)
 static LIBXL_DEFINE_DEVICES_ADD(vtpm)
+
+LIBXL_DEFINE_DEVICE_ADD(vtpm)
 LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 LIBXL_DEFINE_DEVICE_LIST(vtpm)
 
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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